Class: HoN::PlayerHeroStats
- Defined in:
- lib/honclient/player_hero_stats.rb
Instance Attribute Summary collapse
-
#heroes ⇒ Object
Returns the value of attribute heroes.
-
#nickname ⇒ Object
Returns the value of attribute nickname.
Instance Method Summary collapse
- #dump_xml_stats ⇒ Object
- #hero(name) ⇒ Object
-
#initialize(nickname) ⇒ PlayerHeroStats
constructor
A new instance of PlayerHeroStats.
- #stats(hero, key) ⇒ Object
Methods inherited from Stats
#error, #error?, #method_missing, #stat
Constructor Details
#initialize(nickname) ⇒ PlayerHeroStats
Returns a new instance of PlayerHeroStats.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/honclient/player_hero_stats.rb', line 4 def initialize(nickname) @nickname = nickname @heroes = {} begin url = "http://xml.heroesofnewerth.com/xml_requester.php?f=player_hero_stats&opt=nick&nick[]=#{@nickname}" xml_data = Net::HTTP.get_response(URI.parse(url)).body data = Nokogiri::XML.parse(xml_data) data.xpath("//xmlRequest/stats/player_hero_stats/hero").each do |hero| temp = {} hero.children.each do |stat| temp[stat["name"]] = stat.content end @heroes[hero["cli_name"]] = temp end rescue SocketError @error = "Could not contact the Newerth XML API." end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class HoN::Stats
Instance Attribute Details
#heroes ⇒ Object
Returns the value of attribute heroes.
3 4 5 |
# File 'lib/honclient/player_hero_stats.rb', line 3 def heroes @heroes end |
#nickname ⇒ Object
Returns the value of attribute nickname.
3 4 5 |
# File 'lib/honclient/player_hero_stats.rb', line 3 def nickname @nickname end |
Instance Method Details
#dump_xml_stats ⇒ Object
39 40 41 |
# File 'lib/honclient/player_hero_stats.rb', line 39 def dump_xml_stats return @heroes end |
#hero(name) ⇒ Object
23 24 25 |
# File 'lib/honclient/player_hero_stats.rb', line 23 def hero(name) @heroes["Hero_#{name.capitalize}"] end |
#stats(hero, key) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/honclient/player_hero_stats.rb', line 27 def stats(hero,key) if !hero.empty? if @heroes.has_key? hero if @heroes[hero].has_key? key @heroes[hero][key] end end else return 0 end end |