battle_pet 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/battle_pet.rb +19 -11
  2. metadata +1 -1
data/lib/battle_pet.rb CHANGED
@@ -17,17 +17,8 @@ class BattlePet
17
17
  PET_NAMES = YAML.load File.read(File.join(File.dirname(__FILE__), 'battle_pet.yml'))
18
18
 
19
19
  def initialize(id, locale = :us)
20
- url = "http://#{host(locale)}/api/wow/battlePet/species/#{id.to_s}"
21
- info = JSON.parse(open(url).read)
22
- @id = id
23
- @description = info["description"]
24
- @name = find_name(locale)
25
- @source = info["source"]
26
- @can_battle = info["canBattle"]
27
- @type = PetType.find info["petTypeId"]
28
- @creature = info["creatureId"]
29
- @abilities = acquire_abilities info["abilities"]
30
- @added_in_patch = check_patch
20
+ info = get_data_from_api(id, locale)
21
+ set_attributes(info, locale)
31
22
  end
32
23
 
33
24
  def can_battle?
@@ -35,6 +26,23 @@ class BattlePet
35
26
  end
36
27
 
37
28
  protected
29
+
30
+ def get_data_from_api(id, locale)
31
+ url = "http://#{host(locale)}/api/wow/battlePet/species/#{id.to_s}"
32
+ JSON.parse(open(url).read)
33
+ end
34
+
35
+ def set_attributes(hash, locale)
36
+ @id = hash["speciesId"]
37
+ @description = hash["description"]
38
+ @name = find_name(locale)
39
+ @source = hash["source"]
40
+ @can_battle = hash["canBattle"]
41
+ @type = PetType.find hash["petTypeId"]
42
+ @creature = hash["creatureId"]
43
+ @abilities = acquire_abilities hash["abilities"]
44
+ @added_in_patch = check_patch
45
+ end
38
46
 
39
47
  def host(locale)
40
48
  REGION_HOSTS[locale] || REGION_HOSTS[:us]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: battle_pet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: