Class: GlazeAnalyzer::CharacterData
- Inherits:
-
Object
- Object
- GlazeAnalyzer::CharacterData
- Defined in:
- lib/glaze/analyzer/characterdata.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #get_character_spec_names ⇒ Object
-
#initialize(realm, character_name, pvp_spec_id) ⇒ CharacterData
constructor
A new instance of CharacterData.
- #major_glyph_names ⇒ Object
- #pvp_spec ⇒ Object
- #spec_name(spec_id) ⇒ Object
Constructor Details
#initialize(realm, character_name, pvp_spec_id) ⇒ CharacterData
Returns a new instance of CharacterData.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/glaze/analyzer/characterdata.rb', line 6 def initialize(realm, character_name, pvp_spec_id) uri = URI.parse("http://us.battle.net/api/wow/character/#{realm}/#{URI.encode(character_name)}?fields=talents") response = Net::HTTP.get_response(uri) character_data = JSON.parse(response.body) tries = 0 while character_data['talents'] == nil if tries > 3 raise 'Error retrieving character data' end puts "error.. retrying #{character_name} - #{realm} retrying in 5 seconds" response = Net::HTTP.get_response(uri) character_data = JSON.parse(response.body) tries += 1 sleep 5 end @data = character_data @pvp_spec_id = pvp_spec_id end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/glaze/analyzer/characterdata.rb', line 4 def data @data end |
Instance Method Details
#get_character_spec_names ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/glaze/analyzer/characterdata.rb', line 48 def get_character_spec_names begin spec1_name = @data['talents'][0]['spec']['name'] rescue spec1_name = 'nil' end begin spec2_name = @data['talents'][1]['spec']['name'] rescue spec2_name = 'nil' end return spec1_name, spec2_name end |
#major_glyph_names ⇒ Object
64 65 66 67 68 |
# File 'lib/glaze/analyzer/characterdata.rb', line 64 def major_glyph_names @data['talents'][pvp_spec]['glyphs']['major'].map do |glyph| glyph['name'] end end |
#pvp_spec ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/glaze/analyzer/characterdata.rb', line 28 def pvp_spec pvp_spec_name = spec_name(@pvp_spec_id) # eg. Retribution spec1_name, spec2_name = get_character_spec_names # eg. Retribution, Holy if pvp_spec_name == spec1_name && pvp_spec_name == spec2_name if @data['talents'].first['selected'] == true return 0 else return 1 end elsif pvp_spec_name == spec1_name return 0 elsif pvp_spec_name == spec2_name return 1 else return 0 end end |
#spec_name(spec_id) ⇒ Object
70 71 72 73 74 75 76 77 78 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 109 |
# File 'lib/glaze/analyzer/characterdata.rb', line 70 def spec_name(spec_id) spec_names = { 102 => 'Balance', 103 => 'Feral Combat', 104 => 'Guardian', 105 => 'Restoration', 250 => 'Blood', 251 => 'Frost', 252 => 'Unholy', 253 => 'Beast Mastery', 254 => 'Marksmanship', 255 => 'Survival', 256 => 'Discipline', 257 => 'Holy', 258 => 'Shadow', 259 => 'Assassination', 260 => 'Combat', 261 => 'Subtlety', 262 => 'Elemental', 263 => 'Enhancement', 264 => 'Restoration', 265 => 'Affliction', 266 => 'Demonology', 267 => 'Destruction', 268 => 'Brewmaster', 269 => 'Windwalker', 270 => 'Mistweaver', 62 => 'Arcane', 63 => 'Fire', 64 => 'Frost', 65 => 'Holy', 66 => 'Protection', 70 => 'Retribution', 71 => 'Arms', 72 => 'Fury', 73 => 'Protection' } return spec_names[spec_id] end |