Below is what I threw together without the $critical_damage_data hash because it's thousands of lines long. It's not pretty, but it works. You could always use Notepad++ and search your log folder (recursively, if you need) for all lines that match whatever string the TELL has and then look at those. Probably a hell of a lot easier that way if you're not used to writing Ruby. You can use RegEx in the NP++ search if you need.
Code:
$data_output_array = Array.new
$file_output_name = $script_dir + "critical_data_output_" + Time.now.strftime("%Y%m%d%H%M%S") + ".txt"
files = f_files_collect(YOUR_FOLDER_PATH_STRING_HERE);
def f_files_collect(folder_path)
if folder_path[-1, 1] != "/" then
folder_path = folder_path + "/"
end
return Dir[folder_path + "*.txt"]
end
def f_file_parse(file_path, string_start, string_end)
file = File.open(file_path, "r")
iterator = 0
line_start = 0
line_end = 0
lines = Array.new
begin_collect = false
begin_process = false
data_hash = Hash.new
file.each_line {
|line|
if line =~ /#{string_start}/ then
line_start = iterator
begin_collect = true
elsif line =~ /#{string_end}/ and line_start > line_end then
line_end = iterator
begin_collect = false
begin_process = true
end
if begin_collect == true then
lines.push(line)
next
end
if begin_process == true then
output_hash = Hash.new
if !lines.find { |l| l =~ /\.\.\. and hit/ }.nil? then
lines.each {
|l|
if l =~ /^You swing an? ([a-z\-\s]+) at an? ([a-z\-\s]+)/ then
output_hash["weapon"] = $1
output_hash["target"] = $2
elsif l =~ /^ AS\: \+([0-9]+) vs DS\: \+([0-9]+) with AvD\: \+([0-9]+) \+ d100 roll\: \+([0-9]+) \= \+([0-9]+)$/
output_hash["attack_strength"] = $1
output_hash["defense_strength"] = $2
output_hash["attack_vs_defense"] = $3
output_hash["die_roll"] = $4
output_hash["outcome"] = $5
elsif l =~ /\.\.\. and hit for ([0-9]+) points of damage!/
output_hash["total_damage"] = $1
elsif regex = $critical_damage_data.keys.find { |r| l =~ r }
output_hash["damage_type"] = $critical_damage_data[regex]["type"]
output_hash["damage_critical"] = $critical_damage_data[regex]["damage"]
output_hash["critical_rank"] = $critical_damage_data[regex]["rank"]
output_hash["wounds"] = $critical_damage_data[regex]["wounds"]
end
}
$data_output_array.push(output_hash)
end
begin_process = false
lines = Array.new
end
iterator += 1
}
file.close
end
files.each {
|file|
f_file_parse(file, "You swing", "Roundtime")
}
File.open($file_output_name, "w") {
|file|
# header
output_string = ""
$data_output_array[0].each_key {
|key|
output_string += key + "\t"
}
file.puts(output_string[0...-1])
# data
$data_output_array.each {
|data_hash|
output_string = ""
data_hash.each_value {
|val|
output_string += val + "\t"
}
file.puts(output_string[0...-1])
}
}