battle_pet 0.2.8 → 0.2.9

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/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2013 Hegwin Wang
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2013 Hegwin Wang
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,20 +1,20 @@
1
- # BattlePet
2
-
3
- ## Description
4
-
5
- This is a gem to parse the info from WoW BattlePet API.
6
-
7
- ## Usage
8
-
9
- ```ruby
10
- require 'battle_pet'
11
- pet = BattlePet.new(39)
12
- ```
13
-
14
- ## Test
15
-
16
- `$ rake test`
17
-
18
- ## License
19
-
20
- Copyright (c) 2013 Hegwin Wang. See [LICENSE](https://github.com/hegwin/battle_pet/blob/master/LICENSE) for details.
1
+ # BattlePet
2
+
3
+ ## Description
4
+
5
+ This is a gem to parse the info from WoW BattlePet API.
6
+
7
+ ## Usage
8
+
9
+ ```ruby
10
+ require 'battle_pet'
11
+ pet = BattlePet.new(39)
12
+ ```
13
+
14
+ ## Test
15
+
16
+ `$ rake test`
17
+
18
+ ## License
19
+
20
+ Copyright (c) 2013 Hegwin Wang. See [LICENSE](https://github.com/hegwin/battle_pet/blob/master/LICENSE) for details.
data/Rakefile CHANGED
@@ -1,8 +1,8 @@
1
- require 'rake/testtask'
2
-
3
- Rake::TestTask.new do |t|
4
- t.libs << 'test'
5
- end
6
-
7
- desc "Run tests"
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
8
  task :default => :test
@@ -1,16 +1,16 @@
1
- class BattlePet::Ability
2
- attr_accessor :id, :name, :icon ,:type, :cooldown, :rounds
3
-
4
- def initialize(data)
5
- @id = data["id"]
6
- @name = data["name"]
7
- @icon = data["icon"]
8
- @type = BattlePet::Type.find(data["petTypeId"])
9
- @cooldown = data["cooldown"]
10
- @rounds = data["rounds"]
11
- end
12
-
13
- def icon_url
14
- "http://media.blizzard.com/wow/icons/56/#{icon}.jpg"
15
- end
16
- end
1
+ class BattlePet::Ability
2
+ attr_accessor :id, :name, :icon ,:type, :cooldown, :rounds
3
+
4
+ def initialize(data)
5
+ @id = data["id"]
6
+ @name = data["name"]
7
+ @icon = data["icon"]
8
+ @type = BattlePet::Type.find(data["petTypeId"])
9
+ @cooldown = data["cooldown"]
10
+ @rounds = data["rounds"]
11
+ end
12
+
13
+ def icon_url
14
+ "http://media.blizzard.com/wow/icons/56/#{icon}.jpg"
15
+ end
16
+ end
@@ -1,24 +1,24 @@
1
- # encoding: utf-8
2
- class BattlePet::Translator
3
-
4
- def initialize(locale)
5
- @locale = locale
6
- end
7
-
8
- def colon
9
- case @locale
10
- when :cn then ':'
11
- when :tw then ':'
12
- else ': '
13
- end
14
- end
15
-
16
- def cost
17
- case @locale
18
- when :us, :eu then 'Cost'
19
- when :cn then '价格'
20
- when :tw then '花費'
21
- when :kr then '비용'
22
- end
23
- end
24
- end
1
+ # encoding: utf-8
2
+ class BattlePet::Translator
3
+
4
+ def initialize(locale)
5
+ @locale = locale
6
+ end
7
+
8
+ def colon
9
+ case @locale
10
+ when :cn then ':'
11
+ when :tw then ':'
12
+ else ': '
13
+ end
14
+ end
15
+
16
+ def cost
17
+ case @locale
18
+ when :us, :eu then 'Cost'
19
+ when :cn then '价格'
20
+ when :tw then '花費'
21
+ when :kr then '비용'
22
+ end
23
+ end
24
+ end
@@ -1,16 +1,16 @@
1
- class BattlePet::Type
2
- PET_TYPES = { 0 => 'Humanoid',
3
- 1 => 'Dragonkin',
4
- 2 => 'Flying',
5
- 3 => 'Undead',
6
- 4 => 'Critter',
7
- 5 => 'Magic',
8
- 6 => 'Elemental',
9
- 7 => 'Beast',
10
- 8 => 'Aquatic',
11
- 9 => 'Mechanical' }
12
-
13
- def self.find(type_id)
14
- PET_TYPES[type_id]
15
- end
16
- end
1
+ class BattlePet::Type
2
+ PET_TYPES = { 0 => 'Humanoid',
3
+ 1 => 'Dragonkin',
4
+ 2 => 'Flying',
5
+ 3 => 'Undead',
6
+ 4 => 'Critter',
7
+ 5 => 'Magic',
8
+ 6 => 'Elemental',
9
+ 7 => 'Beast',
10
+ 8 => 'Aquatic',
11
+ 9 => 'Mechanical' }
12
+
13
+ def self.find(type_id)
14
+ PET_TYPES[type_id]
15
+ end
16
+ end
data/lib/battle_pet.rb CHANGED
@@ -1,105 +1,109 @@
1
- require 'open-uri'
2
- require 'json'
3
- require 'yaml'
4
-
5
- class BattlePet
6
- attr_accessor :id, :name, :description, :source, :type, :creature, :abilities, :added_in_patch, :icon
7
-
8
- REGION_HOSTS = { us: 'us.battle.net',
9
- eu: 'eu.battle.net',
10
- kr: 'kr.battle.net',
11
- tw: 'tw.battle.net',
12
- cn: 'www.battlenet.com.cn' }
13
-
14
- def initialize(id, locale = :us)
15
- data = BattlePet.parse_data_from_api(id, locale)
16
- set_attributes(data, locale) if data
17
- end
18
-
19
- def can_battle?
20
- @can_battle
21
- end
22
-
23
- def icon_url
24
- "http://media.blizzard.com/wow/icons/56/#{icon}.jpg"
25
- end
26
-
27
- protected
28
-
29
- def self.parse_data_from_api(id, locale)
30
- url = "http://#{host(locale)}/api/wow/battlePet/species/#{id.to_s}"
31
- tried_times = 0
32
- begin
33
- response = open(url)
34
- rescue OpenURI::HTTPError => e
35
- if e.message =~ /404/
36
- warn '[WARNING] Pet ID Incorrect'
37
- elsif e.message =~ /500/
38
- warn '[WARNING] Access denied.'
39
- elsif tried_times < 3
40
- tried_times += 1
41
- retry
42
- end
43
- end
44
- response ? JSON.parse(response.read) : nil
45
- end
46
-
47
- def set_attributes(data, locale)
48
- @id = data["speciesId"]
49
- @name = data["name"]
50
- @description = data["description"]
51
- @icon = data["icon"]
52
- @source = BattlePet.parse_source data["source"], locale
53
- @can_battle = data["canBattle"]
54
- @type = Type.find data["petTypeId"]
55
- @creature = data["creatureId"]
56
- @added_in_patch = BattlePet.check_patch(id)
57
- @abilities = acquire_abilities data["abilities"]
58
- end
59
-
60
- def self.host(locale)
61
- REGION_HOSTS[locale] || REGION_HOSTS[:us]
62
- end
63
-
64
- def acquire_abilities(abilities)
65
- results = {}
66
- abilities.each { |ability| results[ability['requiredLevel']] = Ability.new(ability) }
67
- results
68
- end
69
-
70
- def self.check_patch(id)
71
- case id
72
- when 1..864 then '5.0'
73
- when 865..1013 then '5.1'
74
- when 1014..1213 then '5.2'
75
- else '5.3'
76
- end
77
- end
78
-
79
- def self.parse_source(str_source, locale)
80
- translator = Translator.new(locale)
81
- hash_source = {}
82
- str_source.split(/\n+/).each do |line|
83
- match_data = line.match(translator.colon)
84
- k = match_data.pre_match
85
- v = match_data.post_match.gsub(/\(\d+\)/, '').strip
86
- v = parse_cost(v) if k == translator.cost
87
- hash_source[k] = v
88
- end
89
- hash_source
90
- end
91
-
92
- def self.parse_cost(str_cost)
93
- num = str_cost.match(/^\d*/).to_s
94
- unit = case str_cost
95
- when /GOLDICON/ then 'G'
96
- when /SILVERICON/ then 'S'
97
- else ''
98
- end
99
- num + unit
100
- end
101
- end
102
-
103
- require 'battle_pet/type'
104
- require 'battle_pet/ability'
105
- require 'battle_pet/translator'
1
+ require 'open-uri'
2
+ require 'json'
3
+ require 'yaml'
4
+
5
+ class BattlePet
6
+ attr_accessor :id, :name, :description, :source, :type, :creature, :abilities, :added_in_patch, :icon
7
+
8
+ REGION_HOSTS = { us: 'us.battle.net',
9
+ eu: 'eu.battle.net',
10
+ kr: 'kr.battle.net',
11
+ tw: 'tw.battle.net',
12
+ cn: 'www.battlenet.com.cn' }
13
+
14
+ def initialize(id, locale = :us)
15
+ data = BattlePet.parse_data_from_api(id, locale)
16
+ set_attributes(data, locale) if data
17
+ end
18
+
19
+ def can_battle?
20
+ @can_battle
21
+ end
22
+
23
+ def icon_url
24
+ "http://media.blizzard.com/wow/icons/56/#{icon}.jpg"
25
+ end
26
+
27
+ protected
28
+
29
+ def self.parse_data_from_api(id, locale)
30
+ url = "http://#{host(locale)}/api/wow/battlePet/species/#{id.to_s}"
31
+ tried_times = 0
32
+ begin
33
+ response = open(url)
34
+ rescue OpenURI::HTTPError => e
35
+ if e.message =~ /404/
36
+ warn '[WARNING] Pet ID Incorrect'
37
+ elsif e.message =~ /500/
38
+ warn '[WARNING] Access denied.'
39
+ elsif tried_times < 3
40
+ tried_times += 1
41
+ retry
42
+ end
43
+ end
44
+ response ? JSON.parse(response.read) : nil
45
+ end
46
+
47
+ def set_attributes(data, locale)
48
+ @id = data["speciesId"]
49
+ @name = data["name"]
50
+ @description = data["description"]
51
+ @icon = data["icon"]
52
+ @source = BattlePet.parse_source data["source"], locale
53
+ @can_battle = data["canBattle"]
54
+ @type = Type.find data["petTypeId"]
55
+ @creature = data["creatureId"]
56
+ @added_in_patch = BattlePet.check_patch(id)
57
+ @abilities = acquire_abilities data["abilities"]
58
+ end
59
+
60
+ def self.host(locale)
61
+ REGION_HOSTS[locale] || REGION_HOSTS[:us]
62
+ end
63
+
64
+ def acquire_abilities(abilities)
65
+ results = {}
66
+ abilities.each { |ability| results[ability['requiredLevel']] = Ability.new(ability) }
67
+ results
68
+ end
69
+
70
+ def self.check_patch(id)
71
+ case id
72
+ when 1..864 then '5.0'
73
+ when 865..1013 then '5.1'
74
+ when 1014..1213 then '5.2'
75
+ else '5.3'
76
+ end
77
+ end
78
+
79
+ def self.parse_source(str_source, locale)
80
+ translator = Translator.new(locale)
81
+ hash_source = {}
82
+ str_source.split(/\n+/).each do |line|
83
+ if match_data = line.match(translator.colon)
84
+ k = match_data.pre_match
85
+ v = match_data.post_match.gsub(/\(\d+\)/, '').strip
86
+ v = parse_cost(v) if k == translator.cost
87
+ else
88
+ k = line
89
+ v = ""
90
+ end
91
+ hash_source[k] = v
92
+ end
93
+ hash_source
94
+ end
95
+
96
+ def self.parse_cost(str_cost)
97
+ num = str_cost.match(/^\d*/).to_s
98
+ unit = case str_cost
99
+ when /GOLDICON/ then 'G'
100
+ when /SILVERICON/ then 'S'
101
+ else ''
102
+ end
103
+ num + unit
104
+ end
105
+ end
106
+
107
+ require 'battle_pet/type'
108
+ require 'battle_pet/ability'
109
+ require 'battle_pet/translator'
@@ -1 +1 @@
1
- {"speciesId":39,"petTypeId":9,"creatureId":2671,"name":"机械松鼠","canBattle":true,"icon":"inv_pet_mechanicalsquirrel","description":"机械松鼠体内的逻辑运算中心告诉它,要多多采集坚果和螺栓,以备冬季取用。","source":"专业技能:工程","abilities":[{"slot":2,"order":2,"requiredLevel":4,"id":459,"name":"旋紧发条","icon":"inv_gizmo_02","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":0,"order":3,"requiredLevel":10,"id":202,"name":"痛击","icon":"spell_druid_thrash","cooldown":0,"rounds":1,"petTypeId":7,"isPassive":false,"hideHints":false},{"slot":0,"order":0,"requiredLevel":1,"id":384,"name":"铁拳","icon":"inv_misc_desecrated_plategloves","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":1,"order":1,"requiredLevel":2,"id":389,"name":"超频","icon":"inv_gizmo_03","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":2,"order":5,"requiredLevel":20,"id":278,"name":"修复","icon":"ability_repair","cooldown":5,"rounds":3,"petTypeId":9,"isPassive":false,"hideHints":true},{"slot":1,"order":4,"requiredLevel":15,"id":392,"name":"强化护甲","icon":"inv_misc_wartornscrap_plate","cooldown":4,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":true}]}
1
+ {"speciesId":39,"petTypeId":9,"creatureId":2671,"name":"机械松鼠","canBattle":true,"icon":"inv_pet_mechanicalsquirrel","description":"机械松鼠体内的逻辑运算中心告诉它,要多多采集坚果和螺栓,以备冬季取用。","source":"专业技能:工程","abilities":[{"slot":2,"order":2,"requiredLevel":4,"id":459,"name":"旋紧发条","icon":"inv_gizmo_02","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":0,"order":3,"requiredLevel":10,"id":202,"name":"痛击","icon":"spell_druid_thrash","cooldown":0,"rounds":1,"petTypeId":7,"isPassive":false,"hideHints":false},{"slot":0,"order":0,"requiredLevel":1,"id":384,"name":"铁拳","icon":"inv_misc_desecrated_plategloves","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":1,"order":1,"requiredLevel":2,"id":389,"name":"超频","icon":"inv_gizmo_03","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":2,"order":5,"requiredLevel":20,"id":278,"name":"修复","icon":"ability_repair","cooldown":5,"rounds":3,"petTypeId":9,"isPassive":false,"hideHints":true},{"slot":1,"order":4,"requiredLevel":15,"id":392,"name":"强化护甲","icon":"inv_misc_wartornscrap_plate","cooldown":4,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":true}]}
@@ -1 +1 @@
1
- {"speciesId":39,"petTypeId":9,"creatureId":2671,"name":"Mechanical Squirrel","canBattle":true,"icon":"inv_pet_mechanicalsquirrel","description":"A mechanical squirrel's logic center tells it to collect and store both nuts and bolts for the winter.","source":"Profession: Engineering","abilities":[{"slot":2,"order":2,"requiredLevel":4,"id":459,"name":"Wind-Up","icon":"inv_gizmo_02","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":0,"order":3,"requiredLevel":10,"id":202,"name":"Thrash","icon":"spell_druid_thrash","cooldown":0,"rounds":1,"petTypeId":7,"isPassive":false,"hideHints":false},{"slot":0,"order":0,"requiredLevel":1,"id":384,"name":"Metal Fist","icon":"inv_misc_desecrated_plategloves","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":1,"order":1,"requiredLevel":2,"id":389,"name":"Overtune","icon":"inv_gizmo_03","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":2,"order":5,"requiredLevel":20,"id":278,"name":"Repair","icon":"ability_repair","cooldown":5,"rounds":3,"petTypeId":9,"isPassive":false,"hideHints":true},{"slot":1,"order":4,"requiredLevel":15,"id":392,"name":"Extra Plating","icon":"inv_misc_wartornscrap_plate","cooldown":4,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":true}]}
1
+ {"speciesId":39,"petTypeId":9,"creatureId":2671,"name":"Mechanical Squirrel","canBattle":true,"icon":"inv_pet_mechanicalsquirrel","description":"A mechanical squirrel's logic center tells it to collect and store both nuts and bolts for the winter.","source":"Profession: Engineering","abilities":[{"slot":2,"order":2,"requiredLevel":4,"id":459,"name":"Wind-Up","icon":"inv_gizmo_02","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":0,"order":3,"requiredLevel":10,"id":202,"name":"Thrash","icon":"spell_druid_thrash","cooldown":0,"rounds":1,"petTypeId":7,"isPassive":false,"hideHints":false},{"slot":0,"order":0,"requiredLevel":1,"id":384,"name":"Metal Fist","icon":"inv_misc_desecrated_plategloves","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":1,"order":1,"requiredLevel":2,"id":389,"name":"Overtune","icon":"inv_gizmo_03","cooldown":0,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":false},{"slot":2,"order":5,"requiredLevel":20,"id":278,"name":"Repair","icon":"ability_repair","cooldown":5,"rounds":3,"petTypeId":9,"isPassive":false,"hideHints":true},{"slot":1,"order":4,"requiredLevel":15,"id":392,"name":"Extra Plating","icon":"inv_misc_wartornscrap_plate","cooldown":4,"rounds":1,"petTypeId":9,"isPassive":false,"hideHints":true}]}
@@ -1,59 +1,60 @@
1
- # encoding: utf-8
2
- require 'test/unit'
3
- require 'battle_pet'
4
-
5
- class BattlePetTest < Test::Unit::TestCase
6
- def setup
7
- @pet = BattlePet.new(1150)
8
- end
9
-
10
- def test_initialize
11
- assert_equal 1150, @pet.id
12
- assert_equal "Ashstone Core", @pet.name
13
- assert_equal "The cooled core of Golemagg, it appears to retain some semi-sentient properties.", @pet.description
14
- assert_equal "inv_elemental_eternal_shadow", @pet.icon
15
- assert_equal({ 'Drop' => 'Golemagg the Incinerator', 'Zone' => 'Molten Core' }, @pet.source)
16
- assert_equal true, @pet.can_battle?
17
- assert_equal 68666, @pet.creature
18
- end
19
-
20
- def test_parse_data_from_api
21
- assert_equal JSON.parse(File.read(File.join(File.dirname(__FILE__), 'data/mechanical_squirrel_us.json'))),
22
- BattlePet.parse_data_from_api(39, :us)
23
- end
24
-
25
- def test_host
26
- assert_equal 'us.battle.net', BattlePet.host(:us)
27
- assert_equal 'www.battlenet.com.cn', BattlePet.host(:cn)
28
- assert_equal 'us.battle.net', BattlePet.host(:ca)
29
- end
30
-
31
- def test_check_patch
32
- (1..864).to_a.sample(5) { |i| assert_equal '5.0', BattlePet.check_patch(i) }
33
- (865..1013).to_a.sample(5) { |i| assert_equal '5.1', BattlePet.check_patch(i) }
34
- (1014..1213).to_a.sample(5) { |i| assert_equal '5.2', BattlePet.check_patch(i) }
35
- (1213..1400).to_a.sample(5) { |i| assert_equal '5.3', BattlePet.check_patch(i) }
36
- end
37
-
38
- def test_parse_source
39
- assert_equal({ "Quest" => "Egg Wave", "Zone" => "Mount Hyjal" }, BattlePet.parse_source("Quest: Egg Wave\n\nZone: Mount Hyjal\n\n\n\n", :us))
40
- assert_equal({ "Profession" => "Engineering" }, BattlePet.parse_source("Profession: Engineering", :us))
41
- assert_equal({ "Profession" => "Archaeology" }, BattlePet.parse_source("Profession: Archaeology", :us))
42
- assert_equal({ "Profession" => "Enchanting", "Formula" => "Enchanted Lantern" }, BattlePet.parse_source("Profession: Enchanting (525)\n\nFormula: Enchanted Lantern", :us))
43
- assert_equal({ "Achievement" => "Rock Lover", "Category" => "Quests" }, BattlePet.parse_source("Achievement: Rock Lover\n\nCategory: Quests", :us))
44
- assert_equal({ "Promotion" => "Cataclysm Collector's Edition" }, BattlePet.parse_source("Promotion: Cataclysm Collector's Edition", :us))
45
- assert_equal({ "Promotion" => "StarCraft II: Wings of Liberty Collector's Edition" }, BattlePet.parse_source("Promotion: StarCraft II: Wings of Liberty Collector's Edition", :us))
46
- assert_equal({ "Vendor" => "Guild Vendor", "Zone" => "Stormwind, Orgrimmar", "Cost" => "300G" }, BattlePet.parse_source("Vendor: Guild Vendor\n\nZone: Stormwind, Orgrimmar\n\nCost: 300TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0\n\n", :us))
47
- end
48
-
49
- def test_parse_cost
50
- assert_equal "300G", BattlePet.parse_cost('300TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0')
51
- assert_equal "50S", BattlePet.parse_cost('50TINTERFACE\\MONEYFRAME\\UI-SILVERICON.BLP:0')
52
- assert_equal "90", BattlePet.parse_cost('90 ')
53
- end
54
-
55
- def test_icon_url
56
- assert_equal "http://media.blizzard.com/wow/icons/56/inv_elemental_eternal_shadow.jpg", @pet.icon_url
57
- end
58
-
59
- end
1
+ # encoding: utf-8
2
+ require 'test/unit'
3
+ require 'battle_pet'
4
+
5
+ class BattlePetTest < Test::Unit::TestCase
6
+ def setup
7
+ @pet = BattlePet.new(1150)
8
+ end
9
+
10
+ def test_initialize
11
+ assert_equal 1150, @pet.id
12
+ assert_equal "Ashstone Core", @pet.name
13
+ assert_equal "The cooled core of Golemagg, it appears to retain some semi-sentient properties.", @pet.description
14
+ assert_equal "inv_elemental_eternal_shadow", @pet.icon
15
+ assert_equal({ 'Drop' => 'Golemagg the Incinerator', 'Zone' => 'Molten Core' }, @pet.source)
16
+ assert_equal true, @pet.can_battle?
17
+ assert_equal 68666, @pet.creature
18
+ end
19
+
20
+ def test_parse_data_from_api
21
+ assert_equal JSON.parse(File.read(File.join(File.dirname(__FILE__), 'data/mechanical_squirrel_us.json'))),
22
+ BattlePet.parse_data_from_api(39, :us)
23
+ end
24
+
25
+ def test_host
26
+ assert_equal 'us.battle.net', BattlePet.host(:us)
27
+ assert_equal 'www.battlenet.com.cn', BattlePet.host(:cn)
28
+ assert_equal 'us.battle.net', BattlePet.host(:ca)
29
+ end
30
+
31
+ def test_check_patch
32
+ (1..864).to_a.sample(5) { |i| assert_equal '5.0', BattlePet.check_patch(i) }
33
+ (865..1013).to_a.sample(5) { |i| assert_equal '5.1', BattlePet.check_patch(i) }
34
+ (1014..1213).to_a.sample(5) { |i| assert_equal '5.2', BattlePet.check_patch(i) }
35
+ (1213..1400).to_a.sample(5) { |i| assert_equal '5.3', BattlePet.check_patch(i) }
36
+ end
37
+
38
+ def test_parse_source
39
+ assert_equal({ "Quest" => "Egg Wave", "Zone" => "Mount Hyjal" }, BattlePet.parse_source("Quest: Egg Wave\n\nZone: Mount Hyjal\n\n\n\n", :us))
40
+ assert_equal({ "Profession" => "Engineering" }, BattlePet.parse_source("Profession: Engineering", :us))
41
+ assert_equal({ "Profession" => "Archaeology" }, BattlePet.parse_source("Profession: Archaeology", :us))
42
+ assert_equal({ "Profession" => "Enchanting", "Formula" => "Enchanted Lantern" }, BattlePet.parse_source("Profession: Enchanting (525)\n\nFormula: Enchanted Lantern", :us))
43
+ assert_equal({ "Achievement" => "Rock Lover", "Category" => "Quests" }, BattlePet.parse_source("Achievement: Rock Lover\n\nCategory: Quests", :us))
44
+ assert_equal({ "Promotion" => "Cataclysm Collector's Edition" }, BattlePet.parse_source("Promotion: Cataclysm Collector's Edition", :us))
45
+ assert_equal({ "Promotion" => "StarCraft II: Wings of Liberty Collector's Edition" }, BattlePet.parse_source("Promotion: StarCraft II: Wings of Liberty Collector's Edition", :us))
46
+ assert_equal({ "Vendor" => "Guild Vendor", "Zone" => "Stormwind, Orgrimmar", "Cost" => "300G" }, BattlePet.parse_source("Vendor: Guild Vendor\n\nZone: Stormwind, Orgrimmar\n\nCost: 300TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0\n\n", :us))
47
+ assert_equal({ "Pet Store" => "" }, BattlePet.parse_source("Pet Store", :us))
48
+ end
49
+
50
+ def test_parse_cost
51
+ assert_equal "300G", BattlePet.parse_cost('300TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0')
52
+ assert_equal "50S", BattlePet.parse_cost('50TINTERFACE\\MONEYFRAME\\UI-SILVERICON.BLP:0')
53
+ assert_equal "90", BattlePet.parse_cost('90 ')
54
+ end
55
+
56
+ def test_icon_url
57
+ assert_equal "http://media.blizzard.com/wow/icons/56/inv_elemental_eternal_shadow.jpg", @pet.icon_url
58
+ end
59
+
60
+ end
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.2.8
4
+ version: 0.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-13 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple gem to get data from WoW BattlePet API
15
15
  email: zwt315@163.com