lib/bnet/diablo3/hero.rb in bnet-0.0.3 vs lib/bnet/diablo3/hero.rb in bnet-0.0.4

- old
+ new

@@ -1,11 +1,11 @@ class Bnet::Diablo3::Hero < Bnet::BnetResource attr_accessor :paragon_level, :seasonal, :name, :hero_id, :level, :hardcore, :gender, :dead, :hero_class, :last_update, :active_skills, :passive_skills, :region, :battle_tag, :career, - :items, + :items, :followers, :raw_attributes, # stats :life, :damage, :attack_speed, :armor, :strength, :dexterity, :vitality, :intelligence, :physical_resist, :fire_resist, :cold_resist, :lightning_resist, :poison_resist, :arcane_resist, :crit_damage, @@ -22,11 +22,11 @@ "level" => :level, "hardcore" => :hardcore, "gender" => :gender, "dead" => :dead, "class" => :hero_class, - "last-updated" => :last_updated, + "last-updated" => :last_updated } # TODO:Implement # def career @@ -109,51 +109,46 @@ # Create an instance by passing in the args from the response def self.from_api(response) hero = super(response) + hero.raw_attributes = response + if hero assign_skills_from_raw_skills(hero, response["skills"]) if response["skills"] assign_stats_from_raw_stats(hero, response["stats"]) if response["stats"] assign_items_from_raw_items(hero, response["items"]) if response["items"] + assign_followers_from_raw_followers(hero, response["followers"]) if response["followers"] end return hero end private + def self.assign_followers_from_raw_followers(hero, raw_followers) + hero.followers = raw_followers.collect do |follower_type, follower_props| + Bnet::Diablo3::Follower.from_api(follower_type, follower_props) + end + + return hero + end + def self.assign_items_from_raw_items(hero, raw_items) hero.items = raw_items.collect do |location, item_props| - item = Bnet::Diablo3::Item.new - item.location = location - item.item_id = item_props["id"] - item.name = item_props["name"] - item + Bnet::Diablo3::Item.from_api(location, item_props) end return hero end def self.assign_skills_from_raw_skills(hero, raw_skills) - hero.active_skills = raw_skills["active"].collect do |active| - skill = Bnet::Diablo3::Skill.new - if active["skill"] - skill.name = active["skill"]["name"] - end - if active["rune"] - skill.rune = active["rune"]["name"] - end - - skill + hero.active_skills = raw_skills["active"].collect do |active_skill| + Bnet::Diablo3::Skill.from_api(active_skill) unless active_skill.empty? end - hero.passive_skills = raw_skills["passive"].collect do |passive| - skill = Bnet::Diablo3::Skill.new - if passive["skill"] - skill.name = passive["skill"]["name"] - end - skill + hero.passive_skills = raw_skills["passive"].collect do |passive_skill| + Bnet::Diablo3::Skill.from_api(passive_skill) unless passive_skill.empty? end return hero end