battle_pet 0.2.2 → 0.2.3

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/lib/battle_pet.rb CHANGED
@@ -9,7 +9,7 @@ class BattlePet
9
9
  eu: 'eu.battle.net',
10
10
  kr: 'kr.battle.net',
11
11
  tw: 'tw.battle.net',
12
- cn: 'www.battlenet.com.cn'}
12
+ cn: 'www.battlenet.com.cn' }
13
13
 
14
14
  def initialize(id, locale = :us)
15
15
  data = BattlePet.parse_data_from_api(id, locale)
@@ -59,16 +59,27 @@ class BattlePet
59
59
  end
60
60
 
61
61
  def self.parse_source(str_source, locale)
62
- hash_source = {}
63
62
  translator = Translator.new(locale)
63
+ hash_source = {}
64
64
  str_source.split(/\n+/).each do |line|
65
65
  match_data = line.match(translator.colon)
66
66
  k = match_data.pre_match
67
- v = match_data.post_match.gsub(/\(\d+\)/, '').strip
67
+ v = match_data.post_match.gsub(/\(\d+\)/, '').strip
68
+ v = parse_cost(v) if k == translator.cost
68
69
  hash_source[k] = v
69
70
  end
70
71
  hash_source
71
72
  end
73
+
74
+ def self.parse_cost(str_cost)
75
+ num = str_cost.match(/^\d*/).to_s
76
+ unit = case str_cost
77
+ when /GOLDICON/ then 'G'
78
+ when /SILVERICON/ then 'S'
79
+ else ''
80
+ end
81
+ num + unit
82
+ end
72
83
  end
73
84
 
74
85
  require 'battle_pet/type'
@@ -30,8 +30,13 @@ class BattlePetTest < Test::Unit::TestCase
30
30
  assert_equal({ "Achievement" => "Rock Lover", "Category" => "Quests" }, BattlePet.parse_source("Achievement: Rock Lover\n\nCategory: Quests", :us))
31
31
  assert_equal({ "Promotion" => "Cataclysm Collector's Edition" }, BattlePet.parse_source("Promotion: Cataclysm Collector's Edition", :us))
32
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))
33
+ 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))
34
+ end
35
+
36
+ def test_parse_cost
37
+ assert_equal "300G", BattlePet.parse_cost('300TINTERFACE\\MONEYFRAME\\UI-GOLDICON.BLP:0')
38
+ assert_equal "50S", BattlePet.parse_cost('50TINTERFACE\\MONEYFRAME\\UI-SILVERICON.BLP:0')
39
+ assert_equal "90", BattlePet.parse_cost('90 ')
35
40
  end
36
41
 
37
42
  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.2
4
+ version: 0.2.3
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-03 00:00:00.000000000 Z
12
+ date: 2013-06-04 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