battle_pet 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -6,4 +6,11 @@ This is a gem to parse the info from WoW BattlePet API.
6
6
 
7
7
  ## Usage
8
8
 
9
- `pet = BattlePet.new(pet_id)`
9
+ ```
10
+ require 'battle_pet'
11
+ pet = BattlePet.new(39)
12
+ ```
13
+
14
+ ## Test
15
+
16
+ `$ rake test`
data/lib/battle_pet.rb CHANGED
@@ -31,7 +31,7 @@ class BattlePet
31
31
  @id = data["speciesId"]
32
32
  @name = data["name"]
33
33
  @description = data["description"]
34
- @source = data["source"]
34
+ @source = BattlePet.parse_source data["source"], locale
35
35
  @can_battle = data["canBattle"]
36
36
  @type = Type.find data["petTypeId"]
37
37
  @creature = data["creatureId"]
@@ -57,6 +57,17 @@ class BattlePet
57
57
  else '5.3'
58
58
  end
59
59
  end
60
+
61
+ def self.parse_source(str_source, locale)
62
+ hash_source = {}
63
+ str_source.split(/\n+/).each do |line|
64
+ match_data = line.match(": ")
65
+ k = match_data.pre_match
66
+ v = match_data.post_match.gsub(/\(\d+\)/, '').strip
67
+ hash_source[k] = v
68
+ end
69
+ hash_source
70
+ end
60
71
  end
61
72
 
62
73
  require 'battle_pet/type'
@@ -22,4 +22,16 @@ class BattlePetTest < Test::Unit::TestCase
22
22
  (1213..1400).to_a.sample(5) { |i| assert_equal '5.3', BattlePet.check_patch(i) }
23
23
  end
24
24
 
25
+ def test_parse_source
26
+ assert_equal({ "Quest" => "Egg Wave", "Zone" => "Mount Hyjal" }, BattlePet.parse_source("Quest: Egg Wave\n\nZone: Mount Hyjal\n\n\n\n", :us))
27
+ assert_equal({ "Profession" => "Engineering" }, BattlePet.parse_source("Profession: Engineering", :us))
28
+ assert_equal({ "Profession" => "Archaeology" }, BattlePet.parse_source("Profession: Archaeology", :us))
29
+ assert_equal({ "Profession" => "Enchanting", "Formula" => "Enchanted Lantern" }, BattlePet.parse_source("Profession: Enchanting (525)\n\nFormula: Enchanted Lantern", :us))
30
+ assert_equal({ "Achievement" => "Rock Lover", "Category" => "Quests" }, BattlePet.parse_source("Achievement: Rock Lover\n\nCategory: Quests", :us))
31
+ assert_equal({ "Promotion" => "Cataclysm Collector's Edition" }, BattlePet.parse_source("Promotion: Cataclysm Collector's Edition", :us))
32
+ assert_equal({ "Promotion" => "StarCraft II: Wings of Liberty Collector's Edition" }, BattlePet.parse_source("Promotion: StarCraft II: Wings of Liberty Collector's Edition", :us))
33
+ # TODO
34
+ #assert_equal({ "Vendor" => "Guild Vendor", "Zone" => "Stormwind, Orgrimmar", "Cost" => 300 }, BattlePet.parse_source("Vendor: Guild Vendor\n\nZone: Stormwind, Orgrimmar\n\nCost: 300TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0\n\n", :us))
35
+ end
36
+
25
37
  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.0
4
+ version: 0.2.1
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-05-31 00:00:00.000000000 Z
12
+ date: 2013-06-03 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