class Osrs::Stats

Attributes

stats[RW]

Public Class Methods

new(raw_stats) click to toggle source
# File lib/osrshighscores/stats.rb, line 12
def initialize raw_stats
  @raw_stats = raw_stats
  parse_stats
end

Public Instance Methods

[](skill) click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# File lib/osrshighscores/stats.rb, line 46
def skill_names
  @@skills
end
validate_raw_stats() click to toggle source
# File lib/osrshighscores/stats.rb, line 17
def validate_raw_stats
  raise "incorrect input length" unless @raw_stats.length == 39
end