Class: Osrs::Stats
- Inherits:
-
Object
- Object
- Osrs::Stats
- Defined in:
- lib/osrshighscores/stats.rb
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)
Instance Attribute Summary collapse
-
#stats ⇒ Object
Returns the value of attribute stats.
Instance Method Summary collapse
- #[](skill) ⇒ Object
-
#initialize(raw_stats) ⇒ Stats
constructor
A new instance of Stats.
- #parse_stats ⇒ Object
- #skill_names ⇒ Object
- #validate_raw_stats ⇒ Object
Constructor Details
#initialize(raw_stats) ⇒ Stats
Returns a new instance of Stats.
12 13 14 15 |
# File 'lib/osrshighscores/stats.rb', line 12 def initialize raw_stats @raw_stats = raw_stats parse_stats end |
Instance Attribute Details
#stats ⇒ Object
Returns the value of attribute stats.
3 4 5 |
# File 'lib/osrshighscores/stats.rb', line 3 def stats @stats end |
Instance Method Details
#[](skill) ⇒ Object
50 51 52 53 54 55 |
# File 'lib/osrshighscores/stats.rb', line 50 def [] skill skill = skill.to_s.capitalize raise "non-existant skill lookup" unless @@skills.index(skill) stats[@@skills.index(skill)] end |
#parse_stats ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/osrshighscores/stats.rb', line 21 def parse_stats validate_raw_stats @stats = [] @raw_stats.take(24).each do |line| raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/ stat = line.split(",").map(&:to_i) class << stat def method_missing name, *args case name when :rank return self[0] when :level return self[1] when :xp return self[2] end end end @stats << stat end end |
#skill_names ⇒ Object
46 47 48 |
# File 'lib/osrshighscores/stats.rb', line 46 def skill_names @@skills end |
#validate_raw_stats ⇒ Object
17 18 19 |
# File 'lib/osrshighscores/stats.rb', line 17 def validate_raw_stats raise "incorrect input length" unless @raw_stats.length == 39 end |