app_store_pricing_matrix 1.0.0 → 1.0.1

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.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = app_store_pricing_matrix
1
+ = App Store Pricing Matrix
2
2
 
3
3
  A simple module that holds currencies and prices from the Apple's iOS App Store.
4
4
 
@@ -8,7 +8,13 @@ A simple module that holds currencies and prices from the Apple's iOS App Store.
8
8
 
9
9
  == Usage
10
10
 
11
- Some constants:
11
+ Suppose you find a device locale by NSLocale on an iOS device.
12
+
13
+ NSString* currency = [[NSLocale currentLocale] objectForKey:NSLocaleCurrencyCode];
14
+
15
+ That will give you the currency string like "USD" or "EUR", and this library expects them as a key.
16
+
17
+ Some constants, useful for validation:
12
18
 
13
19
  AppStorePricingMatrix::CUSTOMER_CURRENCIES
14
20
  => ["USD", "MXN", "CAD", "AUD", "NZD", "JPY", "EUR", "DKK", "NOK", "SEK", "CHF", "GBP"]
@@ -36,3 +42,15 @@ To retrieve a developer currency from a given customer currency:
36
42
 
37
43
  AppStorePricingMatrix::REVERSE_CURRENCY_MAP['DKK']
38
44
  => "EUR"
45
+
46
+ == Updating the price table
47
+
48
+ The price table was generated by parsing the exhibit C part of the paid app contract PDF file. As of February 27, 2011, it was versioned as V6.
49
+
50
+ However Apple haven't changed it much so far, it's reasonable to expect changes in the future. When that happens, strip the PDF down to 2 pages only containing the price table, rename it to "input.pdf", put it in the project root, then run the following rake task.
51
+
52
+ rake aspm:generate
53
+
54
+ Then run the spec to verify the generated content:
55
+
56
+ rake
data/Rakefile CHANGED
@@ -49,73 +49,35 @@ namespace :aspm do
49
49
  desc "Parse PDF and generate files"
50
50
  task :generate do
51
51
  require 'pdf-reader'
52
- require 'pp'
53
- require 'yaml'
54
-
52
+
55
53
  receiver = PDF::Reader::RegisterReceiver.new
56
- pdf = PDF::Reader.file("lib/prices/v6.pdf", receiver)
57
-
54
+ pdf = PDF::Reader.file("input.pdf", receiver)
55
+
58
56
  targets = receiver.callbacks.select{|callback| callback[:name] == :show_text }[17..-1].map{|i| i[:args].first }
59
57
  split_at = 11*86-1
60
-
58
+
59
+ page1_headers = [ :tier, :usd, :mxn, :usd_pro, :cad, :cad_pro, :aud, :nzd, :aud_pro, :jpy, :jpy_pro ]
60
+ page2_headers = [ :tier, :eur, :dkk, :nok, :sek, :chf, :eur_pro, :gbp, :gbp_pro ]
61
+
62
+ # Page 1 of Exhibit C
61
63
  page1 = Hash.new{|h,k| h[k] = Array.new }.tap do |hash|
62
64
  targets.each_with_index do |v,i|
63
65
  next if i > split_at
64
- key = case i % 11
65
- when 0
66
- :tier
67
- when 1
68
- :usd
69
- when 2
70
- :mxn
71
- when 3
72
- :usd_pro
73
- when 4
74
- :cad
75
- when 5
76
- :cad_pro
77
- when 6
78
- :aud
79
- when 7
80
- :nzd
81
- when 8
82
- :aud_pro
83
- when 9
84
- :jpy
85
- when 10
86
- :jpy_pro
87
- end
66
+ key = page1_headers[i % 11]
88
67
  hash[key.to_s] << v unless key == :tier
89
68
  end
90
69
  end
91
-
70
+
92
71
  targets = targets[split_at+15..-1]
72
+
73
+ # Page 2 of Exhibit C
93
74
  page2 = Hash.new{|h,k| h[k] = Array.new }.tap do |hash|
94
75
  targets.each_with_index do |v,i|
95
- key = case i % 9
96
- when 0
97
- :tier
98
- when 1
99
- :eur
100
- when 2
101
- :dkk
102
- when 3
103
- :nok
104
- when 4
105
- :sek
106
- when 5
107
- :chf
108
- when 6
109
- :eur_pro
110
- when 7
111
- :gbp
112
- when 8
113
- :gbp_pro
114
- end
76
+ key = page2_headers[i % 9]
115
77
  hash[key.to_s] << v unless key == :tier
116
78
  end
117
79
  end
118
-
80
+
119
81
  whole = page1.merge(page2)
120
82
  whole.keys.each do |key|
121
83
  File.open("lib/prices/#{key}", 'w') {|file| file.write whole[key].join("\n") }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{app_store_pricing_matrix}
8
- s.version = "1.0.0"
8
+ s.version = "1.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kenn Ejima"]
@@ -9,7 +9,7 @@ module AppStorePricingMatrix
9
9
  }
10
10
  CUSTOMER_CURRENCIES = CURRENCY_MAP.values.flatten.map{|i| i.to_s.upcase }
11
11
  DEVELOPER_CURRENCIES = CURRENCY_MAP.keys.map{|i| i.to_s.upcase }
12
-
12
+
13
13
  REVERSE_CURRENCY_MAP = {}.tap do |hash|
14
14
  CURRENCY_MAP.keys.each do |key|
15
15
  CURRENCY_MAP[key].each do |customer_currency|
@@ -17,13 +17,13 @@ module AppStorePricingMatrix
17
17
  end
18
18
  end
19
19
  end
20
-
20
+
21
21
  CUSTOMER_PRICES = {}.tap do |hash|
22
22
  CUSTOMER_CURRENCIES.map do |currency|
23
23
  hash[currency] = File.read("#{File.dirname(__FILE__)}/prices/#{currency}").split("\n")
24
24
  end
25
25
  end
26
-
26
+
27
27
  DEVELOPER_PROCEEDS = {}.tap do |hash|
28
28
  DEVELOPER_CURRENCIES.each do |key|
29
29
  hash[key] = File.read("#{File.dirname(__FILE__)}/prices/#{key}_pro").split("\n")
@@ -1,11 +1,43 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "AppStorePricingMatrix" do
4
- it "should have 0 to 85 tiers each" do
5
- Dir.glob(File.dirname(__FILE__) + '/../lib/prices/*').each do |file|
3
+ module ExampleMethods
4
+ def spec_meat(file, currency)
5
+ context "Currency: #{currency}" do
6
+ it "should have currency table" do
7
+ File.exists?(file).should == true
8
+ end
9
+
6
10
  File.open(file) do |text|
7
- text.readlines.size.should == 86
11
+ lines = text.readlines
12
+
13
+ it "should have 0 to 85 tiers" do
14
+ lines.size.should be(86)
15
+ end
16
+
17
+ it "should verify format of table content" do
18
+ lines.each_with_index do |line,i|
19
+ line.should match(/^\d+(?:\.\d\d)?\n?$/), "Error while reading \"#{File.basename(file)}\", line:#{i+1}"
20
+ end
21
+ end
8
22
  end
9
23
  end
10
24
  end
11
25
  end
26
+ include ExampleMethods
27
+
28
+ describe "AppStorePricingMatrix" do
29
+
30
+ context "Customer Currencies" do
31
+ AppStorePricingMatrix::CUSTOMER_CURRENCIES.each do |currency|
32
+ file = File.expand_path(File.dirname(__FILE__) + "/../lib/prices/#{currency.downcase}")
33
+ spec_meat(file, currency)
34
+ end
35
+ end
36
+
37
+ context "Developer Proceeds" do
38
+ AppStorePricingMatrix::DEVELOPER_CURRENCIES.each do |currency|
39
+ file = File.expand_path(File.dirname(__FILE__) + "/../lib/prices/#{currency.downcase}_pro")
40
+ spec_meat(file, currency)
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: app_store_pricing_matrix
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.0
5
+ version: 1.0.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kenn Ejima
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="
113
113
  - !ruby/object:Gem::Version
114
- hash: -1418794269945295947
114
+ hash: -235884874267453491
115
115
  segments:
116
116
  - 0
117
117
  version: "0"