Class: Covetous::Profile::Career

Inherits:
Shen
  • Object
show all
Defined in:
lib/covetous/profile/career.rb

Instance Attribute Summary

Attributes inherited from Shen

#response, #url

Instance Method Summary collapse

Methods inherited from Shen

#method_missing

Constructor Details

#initialize(battle_tag) ⇒ Career

Returns a new instance of Career.



7
8
9
10
# File 'lib/covetous/profile/career.rb', line 7

def initialize(battle_tag)
  @url = "#{Covetous::Profile::BASE_URL}/#{battle_tag}/"
  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Covetous::Shen

Instance Method Details

#get_hero_details_of(hero_name) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/covetous/profile/career.rb', line 16

def get_hero_details_of(hero_name)
  raise NoHeroFoundForProfileError, "No such hero was found under #{battle_tag}" unless hero_names.include? hero_name
  
  hero_index = hero_names.index hero_name
  battle_tag_for_api = battle_tag.gsub('#', '-')
  Covetous::Profile::Hero.new battle_tag_for_api, heroes[hero_index]['id']
end

#hero_namesObject



12
13
14
# File 'lib/covetous/profile/career.rb', line 12

def hero_names
  heroes.map{ |hero| hero['name'] }
end