battle_pet 0.1.5 → 0.1.6
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 +9 -9
- data/Rakefile +7 -7
- data/lib/battle_pet.rb +69 -69
- data/lib/battle_pet.yml +1995 -1995
- data/lib/pet_ability.rb +11 -11
- data/lib/pet_type.rb +16 -16
- data/test/test_battle_pet.rb +32 -8
- metadata +1 -1
data/lib/pet_ability.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
class PetAbility
|
2
|
-
attr_accessor :id, :name, :type, :cooldown, :rounds
|
3
|
-
|
4
|
-
def initialize(params)
|
5
|
-
@id = params["id"]
|
6
|
-
@name = params["name"]
|
7
|
-
@type = PetType.find(params["petTypeId"])
|
8
|
-
@cooldown = params["cooldown"]
|
9
|
-
@rounds = params["rounds"]
|
10
|
-
end
|
11
|
-
end
|
1
|
+
class PetAbility
|
2
|
+
attr_accessor :id, :name, :type, :cooldown, :rounds
|
3
|
+
|
4
|
+
def initialize(params)
|
5
|
+
@id = params["id"]
|
6
|
+
@name = params["name"]
|
7
|
+
@type = PetType.find(params["petTypeId"])
|
8
|
+
@cooldown = params["cooldown"]
|
9
|
+
@rounds = params["rounds"]
|
10
|
+
end
|
11
|
+
end
|
data/lib/pet_type.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
class PetType
|
2
|
-
PET_TYPES = { 0 => 'Humanoid',
|
3
|
-
1 => 'Dragonkin',
|
4
|
-
2 => 'Flying',
|
5
|
-
3 => 'Undead',
|
6
|
-
4 => 'Critter',
|
7
|
-
5 => 'Magical',
|
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 PetType
|
2
|
+
PET_TYPES = { 0 => 'Humanoid',
|
3
|
+
1 => 'Dragonkin',
|
4
|
+
2 => 'Flying',
|
5
|
+
3 => 'Undead',
|
6
|
+
4 => 'Critter',
|
7
|
+
5 => 'Magical',
|
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/test/test_battle_pet.rb
CHANGED
@@ -1,8 +1,32 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'battle_pet'
|
4
|
+
|
5
|
+
class BattlePetTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
def test_parse_data_from_api
|
8
|
+
assert_equal JSON.parse(File.read(File.join(File.dirname(__FILE__), 'data/mechanical_squirrel_us.json'))),
|
9
|
+
BattlePet.parse_data_from_api(39, :us)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_host
|
13
|
+
assert_equal 'us.battle.net', BattlePet.host(:us)
|
14
|
+
assert_equal 'www.battlenet.com.cn', BattlePet.host(:cn)
|
15
|
+
assert_equal 'us.battle.net', BattlePet.host(:ca)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_find_name
|
19
|
+
assert_equal '机械松鼠', BattlePet.find_name(39, :cn)
|
20
|
+
assert_equal 'Adder', BattlePet.find_name(635, :us)
|
21
|
+
assert_equal nil, BattlePet.find_name(1, :cn)
|
22
|
+
assert_equal nil, BattlePet.find_name(39, :ca)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_check_patch
|
26
|
+
(1..864).to_a.sample(5) { |i| assert_equal '5.0', BattlePet.check_patch(i) }
|
27
|
+
(865..1013).to_a.sample(5) { |i| assert_equal '5.1', BattlePet.check_patch(i) }
|
28
|
+
(1014..1213).to_a.sample(5) { |i| assert_equal '5.2', BattlePet.check_patch(i) }
|
29
|
+
(1213..1400).to_a.sample(5) { |i| assert_equal '5.3', BattlePet.check_patch(i) }
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|