From: Matthew Moss Date: 2008-07-05T02:00:41+09:00 Subject: Re: Statistician II (#168) Here is the complete, sample client file: require 'statistician' class Defense < Statistician::Reportable rule "[The ] wounds you[ with ] for point[s] of [ damage]." rule "You are wounded for point[s] of damage." end class Offense < Statistician::Reportable rule "You wound[ the] [ with ] for point[s] of [ damage]." rule "You reflect point[s] of damage to[ the] ." end class Defeat < Statistician::Reportable rule "You succumb to your wounds." end class Victory < Statistician::Reportable rule "Your mighty blow defeated[ the] ." end class Healing < Statistician::Reportable rule "You heal points of your wounds." rule " heals you for of wound damagepoints." end class Regen < Statistician::Reportable rule "You heal yourself for Power points." rule " heals you for Power points." end class Comment < Statistician::Reportable rule "### ###" end class Ignored < Statistician::Reportable rule " defeated[ the] ." rule " has succumbed to his wounds." rule "You have spotted a creature attempting to move stealthily about." rule "You sense that a creature is nearby but hidden from your sight." rule "[The ] incapacitated you." end if __FILE__ == $0 lotro = Statistician::Reporter.new(Defense, Offense, Defeat, Victory, Healing, Regen, Comment, Ignored) lotro.parse(File.read(ARGV[0])) num = Offense.records.size dmg = Offense.records.inject(0) { |sum, off| sum + Integer(off.amount.gsub(',', '_')) } d = Defense.records[3] puts <<-EOT Number of Offense records: #{num} Total damage inflicted: #{dmg} Average damage per Offense: #{(100.0 * dmg / num).round / 100.0} Defense record 3 indicates that a #{d.name} attacked me using #{d.attack}, doing #{d.amount} points of damage. Unmatched rules: #{lotro.unmatched.join("\n")} Comments: #{Comment.records.map { |c| c.comment }.join("\n")} EOT end And here is the output it generates, using the [hunter.txt][1] data file: Number of Offense records: 1300 Total damage inflicted: 127995 Average damage per Offense: 98.46 Defense record 3 indicates that a Tempest Warg attacked me using Melee Double, doing 108 points of damage. Unmatched rules: The Trap wounds Goblin-town Guard for 128 points of Common damage. Nothing to cure. Comments: Chat Log: Combat 04/04 00:34 AM [1]: http://www.splatbang.com/rubyquiz/files/hunter.zip [2]: http://www.rubyquiz.com/quiz67.html