finished stats, tests and docs for stats

This commit is contained in:
danijoo
2013-12-31 16:42:22 +01:00
parent 0bbca21bcd
commit 471c9d6f71
6 changed files with 89 additions and 41 deletions

View File

@@ -1,40 +1,23 @@
require 'sightstone/stat'
# Ranked stats of a summoner
# @attr [Fixnum] modifyDate date of last modification
# @attr [Fixnum] summonerId id of the summoner
# @attr [Hash<Fixnum, Hash<String, Fixnum>>] champions Statisitc for each champion in a Hash. Each key stands for a champions id (0 is sum of all champs) and returns a Hash<stat, stat_value>.
class RankedStats
attr_accessor :champions, :modifyData, :modifyDateStr, :summonerId
attr_accessor :champions, :modifyDate, :summonerId
def initialize(data)
@summonerId = data['summonerId']
@modifyDate = data['modifyDate']
@modifyDateStr = data['modifyDateStr']
@champions = []
@champions = {}
data['champions'].each do |champ|
@champions << ChampionStats.new(champ)
id = champ['id']
@champions[id] = Hash.new unless @champions.has_key? id
stat_keys = champ['stats'].keys
stat_keys.each do |key|
@champions[id][key] = champ['stats'][key]
end
end
end
end
class ChampionStats
attr_accessor :id, :name, :stats
def initialize(data)
@id = data['id']
@name = data['name']
@stats = []
data['stats'].each do |stat|
@stats << ChampionStat.new(stat)
end
end
end
class ChampionStat < Stat
attr_accessor :count
def initialize(data)
super(data)
@count = data['c']
end
end