battle_pet 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- # BattlePet
2
-
3
- ## Description
4
-
5
- This is a gem to parse the info from WoW BattlePet API.
6
-
7
- ## Usage
8
-
9
- `pet = BattlePet.new(pet_id)`
1
+ # BattlePet
2
+
3
+ ## Description
4
+
5
+ This is a gem to parse the info from WoW BattlePet API.
6
+
7
+ ## Usage
8
+
9
+ `pet = BattlePet.new(pet_id)`
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
data/lib/battle_pet.rb CHANGED
@@ -1,61 +1,61 @@
1
- require 'open-uri'
2
- require 'json'
3
- require 'yaml'
4
-
5
- require_relative 'pet_type.rb'
6
- require_relative 'pet_ability.rb'
7
-
8
- class BattlePet
9
- attr_accessor :id, :name, :description, :source, :type, :creature, :abilities, :added_in_patch
10
-
11
- REGION_HOSTS = { us: 'us.battle.net',
12
- eu: 'eu.battle.net',
13
- kr: 'kr.battle.net',
14
- tw: 'tw.battle.net',
15
- cn: 'www.battlenet.com.cn'}
16
-
17
- PET_NAMES = YAML.load File.read(File.join(File.dirname(__FILE__), 'battle_pet.yml'))
18
-
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
31
- end
32
-
33
- def can_battle?
34
- @can_battle
35
- end
36
-
37
- protected
38
-
39
- def host(locale)
40
- REGION_HOSTS[locale] || REGION_HOSTS[:us]
41
- end
42
-
43
- def find_name(locale)
44
- PET_NAMES[id] && PET_NAMES[id]["name"][locale.to_s]
45
- end
46
-
47
- def acquire_abilities(abilities)
48
- results = {}
49
- abilities.each { |ability| results[ability['requiredLevel']] = PetAbility.new(ability) }
50
- results
51
- end
52
-
53
- def check_patch
54
- case @id
55
- when 1..864 then '5.0'
56
- when 865..1013 then '5.1'
57
- when 1014..1213 then '5.2'
58
- else '5.3'
59
- end
60
- end
61
- end
1
+ require 'open-uri'
2
+ require 'json'
3
+ require 'yaml'
4
+
5
+ require_relative 'pet_type.rb'
6
+ require_relative 'pet_ability.rb'
7
+
8
+ class BattlePet
9
+ attr_accessor :id, :name, :description, :source, :type, :creature, :abilities, :added_in_patch
10
+
11
+ REGION_HOSTS = { us: 'us.battle.net',
12
+ eu: 'eu.battle.net',
13
+ kr: 'kr.battle.net',
14
+ tw: 'tw.battle.net',
15
+ cn: 'www.battlenet.com.cn'}
16
+
17
+ PET_NAMES = YAML.load File.read(File.join(File.dirname(__FILE__), 'battle_pet.yml'))
18
+
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
31
+ end
32
+
33
+ def can_battle?
34
+ @can_battle
35
+ end
36
+
37
+ protected
38
+
39
+ def host(locale)
40
+ REGION_HOSTS[locale] || REGION_HOSTS[:us]
41
+ end
42
+
43
+ def find_name(locale)
44
+ PET_NAMES[id] && PET_NAMES[id]["name"][locale.to_s]
45
+ end
46
+
47
+ def acquire_abilities(abilities)
48
+ results = {}
49
+ abilities.each { |ability| results[ability['requiredLevel']] = PetAbility.new(ability) }
50
+ results
51
+ end
52
+
53
+ def check_patch
54
+ case @id
55
+ when 1..864 then '5.0'
56
+ when 865..1013 then '5.1'
57
+ when 1014..1213 then '5.2'
58
+ else '5.3'
59
+ end
60
+ end
61
+ end