class RsHiscores::Stats
Constants
- Skills
- StatCount
Attributes
raw_stats[RW]
stats[RW]
Public Class Methods
new(raw_stats)
click to toggle source
# File lib/rshiscores/stats.rb, line 15 def initialize raw_stats @raw_stats = raw_stats parse_stats end
Public Instance Methods
[](skill)
click to toggle source
# File lib/rshiscores/stats.rb, line 47 def [] skill skill = skill.to_s.capitalize raise "non-existant skill lookup" unless skills.index(skill) stats[skills.index(skill)] end
method_missing(name, *args)
click to toggle source
Calls superclass method
# File lib/rshiscores/stats.rb, line 54 def method_missing name, *args return self[name] if Skills.include? name.to_s.capitalize super end
parse_stats()
click to toggle source
# File lib/rshiscores/stats.rb, line 35 def parse_stats validate_raw_stats @stats = [] @raw_stats.take(stat_count).each do |line| raise "malformed raw stats" unless line =~ /\d+,\d+,\d+/ stat = Stat.new line.split(",").map(&:to_i) @stats << stat end end
skills()
click to toggle source
# File lib/rshiscores/stats.rb, line 25 def skills self.class::Skills end
stat_count()
click to toggle source
# File lib/rshiscores/stats.rb, line 21 def stat_count self.class::StatCount end
validate_raw_stats()
click to toggle source
# File lib/rshiscores/stats.rb, line 29 def validate_raw_stats if @raw_stats.length < stat_count raise "incorrect input length: expected #{stat_count}, got #{@raw_stats.length}" end end