Class: Bnet::Diablo3::Hero
- Inherits:
-
BnetResource
- Object
- BnetResource
- Bnet::Diablo3::Hero
- Defined in:
- lib/bnet/diablo3/hero.rb
Constant Summary collapse
- PARAMS_MAPPING =
{ "paragonLevel" => :paragon_level, "seasonal" => :seasonal, "name" => :name, "id" => :hero_id, "level" => :level, "hardcore" => :hardcore, "gender" => :gender, "dead" => :dead, "class" => :hero_class, "last-updated" => :last_updated }
Instance Attribute Summary collapse
-
#active_skills ⇒ Object
TODO:Implement def career @career = #DO end.
-
#arcane_resist ⇒ Object
Returns the value of attribute arcane_resist.
-
#armor ⇒ Object
Returns the value of attribute armor.
-
#attack_speed ⇒ Object
Returns the value of attribute attack_speed.
-
#battle_tag ⇒ Object
Returns the value of attribute battle_tag.
-
#block_amount_max ⇒ Object
Returns the value of attribute block_amount_max.
-
#block_amount_min ⇒ Object
Returns the value of attribute block_amount_min.
-
#block_chance ⇒ Object
Returns the value of attribute block_chance.
-
#career ⇒ Object
Returns the value of attribute career.
-
#cold_resist ⇒ Object
Returns the value of attribute cold_resist.
-
#crit_chance ⇒ Object
Returns the value of attribute crit_chance.
-
#crit_damage ⇒ Object
Returns the value of attribute crit_damage.
-
#damage ⇒ Object
Returns the value of attribute damage.
-
#damage_increase ⇒ Object
Returns the value of attribute damage_increase.
-
#damage_reduction ⇒ Object
Returns the value of attribute damage_reduction.
-
#dead ⇒ Object
Returns the value of attribute dead.
-
#dexterity ⇒ Object
Returns the value of attribute dexterity.
-
#fire_resist ⇒ Object
Returns the value of attribute fire_resist.
-
#followers ⇒ Object
Returns the value of attribute followers.
-
#gender ⇒ Object
Returns the value of attribute gender.
-
#gold_find ⇒ Object
Returns the value of attribute gold_find.
-
#hardcore ⇒ Object
Returns the value of attribute hardcore.
-
#hero_class ⇒ Object
Returns the value of attribute hero_class.
-
#hero_id ⇒ Object
Returns the value of attribute hero_id.
-
#intelligence ⇒ Object
Returns the value of attribute intelligence.
-
#items ⇒ Object
Returns the value of attribute items.
-
#last_update ⇒ Object
Returns the value of attribute last_update.
-
#level ⇒ Object
Returns the value of attribute level.
-
#life ⇒ Object
Returns the value of attribute life.
-
#life_on_Hit ⇒ Object
Returns the value of attribute life_on_Hit.
-
#life_per_kill ⇒ Object
Returns the value of attribute life_per_kill.
-
#life_steal ⇒ Object
Returns the value of attribute life_steal.
-
#lightning_resist ⇒ Object
Returns the value of attribute lightning_resist.
-
#magic_find ⇒ Object
Returns the value of attribute magic_find.
-
#name ⇒ Object
Returns the value of attribute name.
-
#paragon_level ⇒ Object
Returns the value of attribute paragon_level.
-
#passive_skills ⇒ Object
Returns the value of attribute passive_skills.
-
#physical_resist ⇒ Object
Returns the value of attribute physical_resist.
-
#poison_resist ⇒ Object
Returns the value of attribute poison_resist.
-
#primary_resource ⇒ Object
Returns the value of attribute primary_resource.
-
#raw_attributes ⇒ Object
Returns the value of attribute raw_attributes.
-
#region ⇒ Object
Returns the value of attribute region.
-
#seasonal ⇒ Object
Returns the value of attribute seasonal.
-
#secondary_resource ⇒ Object
Returns the value of attribute secondary_resource.
-
#strength ⇒ Object
Returns the value of attribute strength.
-
#thorns ⇒ Object
Returns the value of attribute thorns.
-
#vitality ⇒ Object
Returns the value of attribute vitality.
Class Method Summary collapse
-
.find(args) ⇒ Object
Perform a query for the D3 career’s hero.
-
.from_api(response) ⇒ Object
Create an instance by passing in the args from the response.
Instance Method Summary collapse
-
#reload ⇒ Object
TODO Extract finder_args to a method then move this ‘reload ` method to super class.
Methods inherited from BnetResource
Constructor Details
This class inherits a constructor from Bnet::BnetResource
Instance Attribute Details
#active_skills ⇒ Object
TODO:Implement def career
@career = #DO
end
36 37 38 |
# File 'lib/bnet/diablo3/hero.rb', line 36 def active_skills @active_skills end |
#arcane_resist ⇒ Object
Returns the value of attribute arcane_resist.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def arcane_resist @arcane_resist end |
#armor ⇒ Object
Returns the value of attribute armor.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def armor @armor end |
#attack_speed ⇒ Object
Returns the value of attribute attack_speed.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def attack_speed @attack_speed end |
#battle_tag ⇒ Object
Returns the value of attribute battle_tag.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def battle_tag @battle_tag end |
#block_amount_max ⇒ Object
Returns the value of attribute block_amount_max.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def block_amount_max @block_amount_max end |
#block_amount_min ⇒ Object
Returns the value of attribute block_amount_min.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def block_amount_min @block_amount_min end |
#block_chance ⇒ Object
Returns the value of attribute block_chance.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def block_chance @block_chance end |
#career ⇒ Object
Returns the value of attribute career.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def career @career end |
#cold_resist ⇒ Object
Returns the value of attribute cold_resist.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def cold_resist @cold_resist end |
#crit_chance ⇒ Object
Returns the value of attribute crit_chance.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def crit_chance @crit_chance end |
#crit_damage ⇒ Object
Returns the value of attribute crit_damage.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def crit_damage @crit_damage end |
#damage ⇒ Object
Returns the value of attribute damage.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def damage @damage end |
#damage_increase ⇒ Object
Returns the value of attribute damage_increase.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def damage_increase @damage_increase end |
#damage_reduction ⇒ Object
Returns the value of attribute damage_reduction.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def damage_reduction @damage_reduction end |
#dead ⇒ Object
Returns the value of attribute dead.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def dead @dead end |
#dexterity ⇒ Object
Returns the value of attribute dexterity.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def dexterity @dexterity end |
#fire_resist ⇒ Object
Returns the value of attribute fire_resist.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def fire_resist @fire_resist end |
#followers ⇒ Object
Returns the value of attribute followers.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def followers @followers end |
#gender ⇒ Object
Returns the value of attribute gender.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def gender @gender end |
#gold_find ⇒ Object
Returns the value of attribute gold_find.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def gold_find @gold_find end |
#hardcore ⇒ Object
Returns the value of attribute hardcore.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def hardcore @hardcore end |
#hero_class ⇒ Object
Returns the value of attribute hero_class.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def hero_class @hero_class end |
#hero_id ⇒ Object
Returns the value of attribute hero_id.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def hero_id @hero_id end |
#intelligence ⇒ Object
Returns the value of attribute intelligence.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def intelligence @intelligence end |
#items ⇒ Object
Returns the value of attribute items.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def items @items end |
#last_update ⇒ Object
Returns the value of attribute last_update.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def last_update @last_update end |
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def level @level end |
#life ⇒ Object
Returns the value of attribute life.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def life @life end |
#life_on_Hit ⇒ Object
Returns the value of attribute life_on_Hit.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def life_on_Hit @life_on_Hit end |
#life_per_kill ⇒ Object
Returns the value of attribute life_per_kill.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def life_per_kill @life_per_kill end |
#life_steal ⇒ Object
Returns the value of attribute life_steal.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def life_steal @life_steal end |
#lightning_resist ⇒ Object
Returns the value of attribute lightning_resist.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def lightning_resist @lightning_resist end |
#magic_find ⇒ Object
Returns the value of attribute magic_find.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def magic_find @magic_find end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def name @name end |
#paragon_level ⇒ Object
Returns the value of attribute paragon_level.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def paragon_level @paragon_level end |
#passive_skills ⇒ Object
Returns the value of attribute passive_skills.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def passive_skills @passive_skills end |
#physical_resist ⇒ Object
Returns the value of attribute physical_resist.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def physical_resist @physical_resist end |
#poison_resist ⇒ Object
Returns the value of attribute poison_resist.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def poison_resist @poison_resist end |
#primary_resource ⇒ Object
Returns the value of attribute primary_resource.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def primary_resource @primary_resource end |
#raw_attributes ⇒ Object
Returns the value of attribute raw_attributes.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def raw_attributes @raw_attributes end |
#region ⇒ Object
Returns the value of attribute region.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def region @region end |
#seasonal ⇒ Object
Returns the value of attribute seasonal.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def seasonal @seasonal end |
#secondary_resource ⇒ Object
Returns the value of attribute secondary_resource.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def secondary_resource @secondary_resource end |
#strength ⇒ Object
Returns the value of attribute strength.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def strength @strength end |
#thorns ⇒ Object
Returns the value of attribute thorns.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def thorns @thorns end |
#vitality ⇒ Object
Returns the value of attribute vitality.
3 4 5 |
# File 'lib/bnet/diablo3/hero.rb', line 3 def vitality @vitality end |
Class Method Details
.find(args) ⇒ Object
Perform a query for the D3 career’s hero
Arguments
Required
:battle_tag - Player Battletag (ex. PlayerOne#1309)
:region - Account region (ex. 'us')
:hero_id - You can get this from an existing Career object
or from the website url when you view a hero
Optional
:locale - String locale (default: 'en_US')
:api_key - String API key
Example
Bnet::Diablo3::Hero.find(battle_tag: ‘PlayerOne-1309’, region: ‘us’, hero_id: 1304986)
Returns a Hero object with the following attributes
:paragon_level, :seasonal, :name, :hero_id,
:level, :hardcore, :gender, :dead, :hero_class, :last_update,
:active_skills, :passive_skills, :region, :battle_tag, :career
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/bnet/diablo3/hero.rb', line 79 def self.find args battle_tag = args[:battle_tag] region = args[:region] hero_id = args[:hero_id] locale = args[:locale] || 'en_US' api_key = args[:api_key] || Bnet.configuration.api_key if battle_tag battle_tag.gsub!('#', '-') end base_api = Bnet::Diablo3.new(region: region) call_url = base_api.url + "profile/#{battle_tag}/hero/#{hero_id}?apikey=#{api_key}&locale=#{locale}" begin data = open(call_url) raw_response = JSON.parse(data.read) if Bnet::API.valid_call?(data.status, raw_response) bnet_object = from_api(raw_response) else bnet_object = nil end rescue OpenURI::HTTPError => e bnet_object = nil end return bnet_object end |
.from_api(response) ⇒ Object
Create an instance by passing in the args from the response
111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/bnet/diablo3/hero.rb', line 111 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 |
Instance Method Details
#reload ⇒ Object
TODO Extract finder_args to a method then move this ‘reload ` method to super class
50 51 52 53 54 55 56 |
# File 'lib/bnet/diablo3/hero.rb', line 50 def reload finder_args = {battle_tag: battle_tag, region: region, hero_id: hero_id} fetched_record = self.class.find(finder_args) fetched_record.instance_variables.each do |ivar| self.instance_variable_set(ivar, fetched_record.instance_variable_get(ivar)) end end |