Class: RsHighscores::Stats
- Inherits:
-
Object
- Object
- RsHighscores::Stats
- Defined in:
- lib/rshighscores/stats.rb
Direct Known Subclasses
Constant Summary collapse
- Skills =
%w(Overall Attack Defence Strength Hitpoints Ranged Prayer Magic Cooking Woodcutting Fletching Fishing Firemaking Crafting Smithing Mining Herblore Agility Thieving Slayer Farming Runecrafting Hunter Construction Summoning Dungeoneering Divination)
- ExpectedStatCount =
44
- ActualStatCount =
27
Instance Attribute Summary collapse
-
#raw_stats ⇒ Object
Returns the value of attribute raw_stats.
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
- #[](skill) ⇒ Object
-
#initialize(raw_stats) ⇒ Stats
constructor
A new instance of Stats.
- #method_missing(name, *args) ⇒ Object
- #parse_stats ⇒ Object
- #validate_raw_stats ⇒ Object
Constructor Details
#initialize(raw_stats) ⇒ Stats
Returns a new instance of Stats.
16 17 18 19 20 |
# File 'lib/rshighscores/stats.rb', line 16 def initialize raw_stats @raw_stats = raw_stats parse_stats end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
45 46 47 48 |
# File 'lib/rshighscores/stats.rb', line 45 def method_missing name, *args return self[name] if Skills.include? name.to_s.capitalize raise NoMethodError end |
Instance Attribute Details
#raw_stats ⇒ Object
Returns the value of attribute raw_stats.
14 15 16 |
# File 'lib/rshighscores/stats.rb', line 14 def raw_stats @raw_stats end |
#stats ⇒ Object
Returns the value of attribute stats.
14 15 16 |
# File 'lib/rshighscores/stats.rb', line 14 def stats @stats end |
Instance Method Details
#[](skill) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/rshighscores/stats.rb', line 38 def [] skill skill = skill.to_s.capitalize raise "non-existant skill lookup" unless self.class::Skills.index(skill) stats[self.class::Skills.index(skill)] end |
#parse_stats ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rshighscores/stats.rb', line 26 def parse_stats validate_raw_stats @stats = [] @raw_stats.take(self.class::ActualStatCount).each do |line| raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/ stat = Stat.new line.split(",").map(&:to_i) @stats << stat end end |
#validate_raw_stats ⇒ Object
22 23 24 |
# File 'lib/rshighscores/stats.rb', line 22 def validate_raw_stats raise "incorrect input length" unless @raw_stats.length == self.class::ExpectedStatCount end |