parseitc 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -14,10 +14,12 @@ h2. SYNOPSIS:
14
14
  bc. require 'rubygems'
15
15
  require 'lib/parseitc'
16
16
  include ParseITC
17
- reports = TransactionParser.new('/path/to/tsv/file1')
18
- reports.add_file('/path/to/tsv/file2')
19
- by_country = report.numbers_by_country
20
- by_country.sort.each {|k, v| puts "#{k}: #{v}"}
17
+
18
+ report = Parser.new('/path/to/tsv/file1')
19
+ report.add_file('/path/to/tsv/file2')
20
+ report.count_by_price_tier.sort.each do |k, v|
21
+ puts "#{k}: #{v}"
22
+ end
21
23
 
22
24
  h2. REQUIREMENTS:
23
25
 
data/demo.rb CHANGED
@@ -3,14 +3,37 @@ require 'lib/parseitc'
3
3
  include ParseITC
4
4
 
5
5
  begin
6
- report = TransactionParser.new('demo1.txt')
6
+ report = Parser.new('demo1.txt')
7
7
  report.add_file('demo2.txt')
8
- by_country = report.numbers_by_country
9
- by_country.sort.each {|k, v| puts "#{k}: #{v}"}
10
- by_date = report.numbers_by_date
11
- by_date.sort.each {|k, v| puts "#{k}: #{v}"}
12
- by_royalty_currency = report.numbers_by_price_tier
13
- by_royalty_currency.sort.each {|k, v| puts "#{k}: #{v}"}
8
+
9
+ puts '=' * 20
10
+ puts "Sales in top 10 countries"
11
+ report.count_by_country.sort_by{|k,v| v}.reverse[0..9].each do |k, v|
12
+ puts " #{k}: #{v}"
13
+ end
14
+
15
+ puts
16
+ puts '=' * 20
17
+ puts "Sales volume per day"
18
+ report.count_by_date.sort.each do |k, v|
19
+ puts " #{k}: #{v}"
20
+ end
21
+
22
+ puts
23
+ puts '=' * 20
24
+ puts "Sales by price and date"
25
+ total = 0
26
+ report.split_by_date.sort.each do |k1, v1|
27
+ puts " #{k1}"
28
+ v1.count_by_price_tier.sort.each do |k2, v2|
29
+ dollars = ApplePricing[:usd][k2]
30
+ puts " $ #{dollars.to_f}: #{v2}"
31
+ total += dollars.to_f * v2
32
+ end
33
+ end
34
+ puts "Revenue: $#{total/7*10} "
35
+ puts "Profit: $#{total} "
36
+
14
37
  rescue Errno::ENOENT
15
38
  puts "The data file you specified was not found"
16
39
  rescue Errno::EACCES
@@ -0,0 +1,83 @@
1
+ require 'lib/parseitc/transaction'
2
+
3
+ module ParseITC
4
+ class Parser
5
+ attr_accessor :transactions
6
+ Version = '0.1.3'
7
+ # files can be either string or array
8
+ def initialize(files=[])
9
+ @transactions = []
10
+ add_files files
11
+ end
12
+
13
+ def add_files files
14
+ [files].flatten.each do |file|
15
+ add_file file
16
+ end
17
+ end
18
+
19
+ def add_file file
20
+ lines = File.readlines(file)
21
+ lines.shift if lines.first.match(/^Provider/)
22
+ lines.each do |xion|
23
+ add_transaction xion
24
+ end
25
+ end
26
+
27
+ def add_transaction transaction
28
+ @transactions << Transaction.new(transaction.split(/\t|\n/))
29
+ end
30
+
31
+ private
32
+ def method_missing(method_id, *arguments)
33
+ match = /split_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
34
+ if match
35
+ split_by(match)
36
+ else
37
+ match = /count_by_([_a-zA-Z]\w*)|numbers_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
38
+ if match
39
+ count_by(match)
40
+ else
41
+ super
42
+ end
43
+ end
44
+ end
45
+
46
+ def split_by(match)
47
+ field = match.captures.first
48
+ raise NoMethodError.new("#{match}") unless @transactions.first.has_field? field
49
+ split_by_field field
50
+ end
51
+
52
+ def split_by_field field
53
+ values = {}
54
+ @transactions.each do |xion|
55
+ value = xion.send(field.to_sym)
56
+ values[value] ||= Parser.new
57
+ values[value].transactions << xion
58
+ end
59
+ values
60
+ end
61
+
62
+ def count_by(match)
63
+ field = match.captures.first
64
+ raise NoMethodError.new("#{match}") unless @transactions.first.has_field? field
65
+ get_count_by_field field
66
+ end
67
+
68
+ def get_count_by_field field
69
+ values = {}
70
+ @transactions.each do |xion|
71
+ value = xion.send(field.to_sym)
72
+ values[value] = (values[value] || 0) + xion.units.to_i
73
+ end
74
+ values
75
+ end
76
+
77
+ # end private
78
+ end
79
+
80
+ # deprecated
81
+ class TransactionParser < Parser
82
+ end
83
+ end
@@ -0,0 +1,73 @@
1
+ module ParseITC
2
+ class Transaction
3
+ YEAR_TWO_THOUSAND = Date.parse("1/1/2000")
4
+ TWO_THOUSAND_YEARS = YEAR_TWO_THOUSAND - Date.parse("1/1/0")
5
+
6
+ # ignoring some columns that are ignored by iphone apps
7
+ attr_accessor :provider, # Apple (always)
8
+ :provider_country, # US (always?)
9
+ :company, # company x
10
+ :product, # widgets and sprockets
11
+ :vendor_identifier, # id you give the product
12
+ :date, # just take the begin date
13
+ :units,
14
+ :royalty_price, # this is what you get paid
15
+ :royalty_currency,
16
+ :customer_price,
17
+ :customer_currency,
18
+ :vendor_offer_code,
19
+ :promo_code,
20
+ :country,
21
+ :apple_identifier # itunes link id
22
+
23
+ alias :price :royalty_price
24
+
25
+ def initialize array
26
+ raise WrongNumberOfElements.new(27, array.length) unless array.length == 27
27
+ @provider = array[0]
28
+ @provider_country = array[1]
29
+ @company = array[5]
30
+ @product = array[6]
31
+ @vendor_identifier = array[2]
32
+ @date = Date.parse(array[11])
33
+ @units = array[9]
34
+ @royalty_price = array[10]
35
+ @royalty_currency = array[15]
36
+ @customer_price = array[20]
37
+ @customer_currency = array[13]
38
+ @vendor_offer_code = array[23]
39
+ @promo_code = array[25]
40
+ @country = array[14]
41
+ @apple_identifier = array[19]
42
+
43
+ # Adjust date if necessary ("1/5/10" should not be 10 A.D.)
44
+ @date += TWO_THOUSAND_YEARS if @date < YEAR_TWO_THOUSAND
45
+ raise PriceTierNotFound.new(royalty_price, royalty_currency) unless price_tier
46
+ end
47
+
48
+ def price_tier
49
+ @price_tier ||= begin
50
+ prices = ApplePricing[@royalty_currency.downcase.to_sym]
51
+ prices.find_index(@royalty_price.to_f)
52
+ rescue
53
+ nil
54
+ end
55
+ end
56
+
57
+ def has_field? field
58
+ (instance_variables.map{|variable| variable[1..-1]} + public_methods).include? field
59
+ end
60
+ end
61
+
62
+ class WrongNumberOfElements < Exception
63
+ def initialize(expected, actual)
64
+ super "Invalid number of elements (#{actual}). Expected #{expected} values"
65
+ end
66
+ end
67
+
68
+ class PriceTierNotFound < Exception
69
+ def initialize(amount, currency)
70
+ super "No price tier found for #{amount} #{currency}"
71
+ end
72
+ end
73
+ end
data/lib/parseitc.rb CHANGED
@@ -1,114 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- module ParseITC
3
- class TransactionParser
4
- attr_accessor :transactions
5
- Version = '0.1.2'
6
- # files can be either string or array
7
- def initialize(files=[])
8
- @transactions = []
9
- [files].flatten.each do |file|
10
- add_file file
11
- end
12
- end
13
-
14
- def add_file file
15
- lines = File.readlines(file)
16
- lines.shift if lines.first.match(/^Provider/)
17
- lines.each do |xion|
18
- add_transaction xion
19
- end
20
- end
21
-
22
- def add_transaction transaction
23
- @transactions << Transaction.new(transaction.split(/\t|\n/))
24
- end
25
-
26
- private
27
- def method_missing(method_id, *arguments)
28
- match = /numbers_by_([_a-zA-Z]\w*)/.match(method_id.to_s)
29
- if match
30
- numbers_by(match)
31
- else
32
- super
33
- end
34
- end
35
-
36
- def allowed_fields
37
- first_xion = @transactions.first
38
- first_xion.instance_variables.map{|field| field[1..-1]} +
39
- first_xion.public_methods
40
- end
41
-
42
- def numbers_by(match)
43
- field = match.captures.first
44
- raise NoMethodError.new("#{match}") unless allowed_fields.include? field
45
- values = {}
46
- @transactions.map do |xion|
47
- value = xion.send(field.to_sym)
48
- values[value] = (values[value] || 0) + xion.units.to_i
49
- end
50
- values
51
- end
52
- # end private
53
- end
54
-
55
- class Transaction
56
- YEAR_TWO_THOUSAND = Date.parse("1/1/2000")
57
- TWO_THOUSAND_YEARS = YEAR_TWO_THOUSAND - Date.parse("1/1/0")
58
2
 
59
- # ignoring some columns that are ignored by iphone apps
60
- attr_accessor :provider, # Apple (always)
61
- :provider_country, # US (always?)
62
- :company, # company x
63
- :product, # widgets and sprockets
64
- :vendor_identifier, # id you give the product
65
- :date, # just take the begin date
66
- :units,
67
- :royalty_price, # this is what you get paid
68
- :royalty_currency,
69
- :customer_price,
70
- :customer_currency,
71
- :vendor_offer_code,
72
- :promo_code,
73
- :country,
74
- :apple_identifier # itunes link id
75
-
76
- alias :price :royalty_price
77
-
78
- def initialize array
79
- raise WrongNumberOfElementsException.new(27, array.length) unless array.length == 27
80
- @provider = array[0]
81
- @provider_country = array[1]
82
- @company = array[5]
83
- @product = array[6]
84
- @vendor_identifier = array[2]
85
- @date = Date.parse(array[11])
86
- @units = array[9]
87
- @royalty_price = array[10]
88
- @royalty_currency = array[15]
89
- @customer_price = array[20]
90
- @customer_currency = array[13]
91
- @vendor_offer_code = array[23]
92
- @promo_code = array[25]
93
- @country = array[14]
94
- @apple_identifier = array[19]
95
-
96
- # Adjust date if necessary ("1/5/10" should not be 10 A.D.)
97
- @date += TWO_THOUSAND_YEARS if @date < YEAR_TWO_THOUSAND
98
- end
99
-
100
- def price_tier
101
- prices = ApplePricing[@royalty_currency.downcase.to_sym]
102
- prices.find_index(@royalty_price.to_f)
103
- end
104
- end
105
-
106
- class WrongNumberOfElementsException < Exception
107
- def initialize(expected, actual)
108
- super "Invalid number of elements (#{actual}). Expected #{expected} values"
109
- end
110
- end
3
+ require 'lib/parseitc/transaction'
4
+ require 'lib/parseitc/parser'
111
5
 
6
+ module ParseITC
112
7
  # pricing tier info
113
8
  ApplePricing = {
114
9
  :usd => [0, 0.7, 1.4, 2.1, 2.8, 3.5, 4.2, 4.9, 5.6, 6.3, 7, 7.7, 8.4, 9.1, 9.8, 10.5, 11.2, 11.9, 12.6, 13.3, 14, 14.7, 15.4, 16.1, 16.8, 17.5, 18.2, 18.9, 19.6, 20.3, 21, 21.7, 22.4, 23.1, 23.8, 24.5, 25.2, 25.9, 26.6, 27.3, 28, 28.7, 29.4, 30.1, 30.8, 31.5, 32.2, 32.9, 33.6, 34.3, 35, 38.5, 42, 45.5, 49, 52.5, 56, 59.5, 63, 66.5, 70, 77, 84, 91, 98, 105, 112, 119, 126, 133, 140, 147, 154, 161, 168, 175, 210, 245, 280, 315, 350, 420, 490, 560, 630, 700],
@@ -0,0 +1,54 @@
1
+ Provider Provider Country Vendor Identifier UPC ISRC Artist / Show Title / Episode / Season Label/Studio/Network Product Type Identifier Units Royalty Price Begin Date End Date Customer Currency Country Code Royalty Currency Preorder Season Pass ISAN Apple Identifier Customer Price CMA Asset/Content Flavor Vendor Offer Code Grid Promo Code Parent Identifier
2
+ qwef APPLE US 000000001 Acme Corp Widgets 1 1 0 1/21/10 1/21/10 USD US USD 350525324 0 CR-RW
3
+ APPLE US 000000001 Acme Corp Widgets 1 2 1.4 01/21/2010 01/21/2010 CAD CA CAD 350525324 1.99
4
+ APPLE US 000000000 Acme Corp Sprockets 1 13 0 01/21/2010 01/21/2010 USD HK USD 350523538 0
5
+ APPLE US 000000000 Acme Corp Sprockets 1 11 0 01/21/2010 01/21/2010 USD CN USD 350523538 0
6
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD AE USD 350523538 0
7
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 EUR RO EUR 350523538 0
8
+ APPLE US 000000000 Acme Corp Sprockets 1 463 0 01/21/2010 01/21/2010 USD US USD 350523538 0
9
+ APPLE US 000000000 Acme Corp Sprockets 1 4 0 01/21/2010 01/21/2010 EUR LU EUR 350523538 0
10
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD CO USD 350523538 0
11
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD EC USD 350523538 0
12
+ APPLE US 000000000 Acme Corp Sprockets 1 151 0 01/21/2010 01/21/2010 EUR DE EUR 350523538 0
13
+ APPLE US 000000001 Acme Corp Widgets 1 1 .97 01/21/2010 01/21/2010 EUR IT EUR 350525324 1.59
14
+ APPLE US 000000000 Acme Corp Sprockets 1 34 0 01/21/2010 01/21/2010 EUR NL EUR 350523538 0
15
+ APPLE US 000000000 Acme Corp Sprockets 1 28 0 01/21/2010 01/21/2010 EUR ES EUR 350523538 0
16
+ APPLE US 000000000 Acme Corp Sprockets 1 20 0 01/21/2010 01/21/2010 SEK SE EUR 350523538 0
17
+ APPLE US 000000000 Acme Corp Sprockets 1 12 0 01/21/2010 01/21/2010 NOK NO EUR 350523538 0
18
+ APPLE US 000000000 Acme Corp Sprockets 1 45 0 01/21/2010 01/21/2010 CHF CH EUR 350523538 0
19
+ APPLE US 000000000 Acme Corp Sprockets 1 24 0 01/21/2010 01/21/2010 AUD AU AUD 350523538 0
20
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 USD TW USD 350523538 0
21
+ APPLE US 000000000 Acme Corp Sprockets 1 8 0 01/21/2010 01/21/2010 EUR PL EUR 350523538 0
22
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 EUR HU EUR 350523538 0
23
+ APPLE US 000000000 Acme Corp Sprockets 1 5 0 01/21/2010 01/21/2010 EUR CZ EUR 350523538 0
24
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 EUR SK EUR 350523538 0
25
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD AR USD 350523538 0
26
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 EUR FI EUR 350523538 0
27
+ APPLE US 000000000 Acme Corp Sprockets 1 41 0 01/21/2010 01/21/2010 JPY JP JPY 350523538 0
28
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD IN USD 350523538 0
29
+ APPLE US 000000000 Acme Corp Sprockets 1 7 0 01/21/2010 01/21/2010 MXN MX USD 350523538 0
30
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD TH USD 350523538 0
31
+ APPLE US 000000000 Acme Corp Sprockets 1 9 0 01/21/2010 01/21/2010 USD IL USD 350523538 0
32
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD LB USD 350523538 0
33
+ APPLE US 000000000 Acme Corp Sprockets 1 5 0 01/21/2010 01/21/2010 EUR AT EUR 350523538 0
34
+ APPLE US 000000001 Acme Corp Widgets 1 1 1.58 01/21/2010 01/21/2010 NZD NZ AUD 350525324 2.59
35
+ APPLE US 000000000 Acme Corp Sprockets 1 12 0 01/21/2010 01/21/2010 USD RU USD 350523538 0
36
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD PK USD 350523538 0
37
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD SA USD 350523538 0
38
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD HR USD 350523538 0
39
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD EG USD 350523538 0
40
+ APPLE US 000000001 Acme Corp Widgets 1 16 1.4 01/21/2010 01/21/2010 USD US USD 350525324 1.99
41
+ APPLE US 000000001 Acme Corp Widgets 1 3 .72 01/21/2010 01/21/2010 GBP GB GBP 350525324 1.19
42
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 EUR PT EUR 350523538 0
43
+ APPLE US 000000000 Acme Corp Sprockets 1 208 0 01/21/2010 01/21/2010 CAD CA CAD 350523538 0
44
+ APPLE US 000000000 Acme Corp Sprockets 1 15 0 01/21/2010 01/21/2010 DKK DK EUR 350523538 0
45
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 NZD NZ AUD 350523538 0
46
+ APPLE US 000000000 Acme Corp Sprockets 1 204 0 01/21/2010 01/21/2010 GBP GB GBP 350523538 0
47
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 EUR IE EUR 350523538 0
48
+ APPLE US 000000000 Acme Corp Sprockets 1 104 0 01/21/2010 01/21/2010 EUR IT EUR 350523538 0
49
+ APPLE US 000000000 Acme Corp Sprockets 1 11 0 01/21/2010 01/21/2010 USD SG USD 350523538 0
50
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD KW USD 350523538 0
51
+ APPLE US 000000000 Acme Corp Sprockets 1 230 0 01/21/2010 01/21/2010 EUR FR EUR 350523538 0
52
+ APPLE US 000000000 Acme Corp Sprockets 1 8 0 01/21/2010 01/21/2010 EUR BE EUR 350523538 0
53
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 EUR GR EUR 350523538 0
54
+ APPLE US 000000000 Acme Corp Sprockets 1 9 0 01/21/2010 01/21/2010 USD TR USD 350523538 0
@@ -0,0 +1,54 @@
1
+ Provider Provider Country Vendor Identifier UPC ISRC Artist / Show Title / Episode / Season Label/Studio/Network Product Type Identifier Units Royalty Price Begin Date End Date Customer Currency Country Code Royalty Currency Preorder Season Pass ISAN Apple Identifier Customer Price CMA Asset/Content Flavor Vendor Offer Code Grid Promo Code Parent Identifier
2
+ APPLE US 000000001 Acme Corp Widgets 1 1 0 1/21/10 1/21/10 USD US USD 350525324 0 CR-RW
3
+ APPLE US 000000001 Acme Corp Widgets 1 2 1.4 01/21/2010 01/21/2010 CAD CA CAD 350525324 1.99
4
+ APPLE US 000000000 Acme Corp Sprockets 1 13 0 01/21/2010 01/21/2010 USD HK USD 350523538 0
5
+ APPLE US 000000000 Acme Corp Sprockets 1 11 0 01/21/2010 01/21/2010 USD CN USD 350523538 0
6
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD AE USD 350523538 0
7
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 EUR RO EUR 350523538 0
8
+ APPLE US 000000000 Acme Corp Sprockets 1 463 0 01/21/2010 01/21/2010 USD US USD 350523538 0
9
+ APPLE US 000000000 Acme Corp Sprockets 1 4 0 01/21/2010 01/21/2010 EUR LU EUR 350523538 0
10
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD CO USD 350523538 0
11
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD EC USD 350523538 0
12
+ APPLE US 000000000 Acme Corp Sprockets 1 151 0 01/21/2010 01/21/2010 EUR DE EUR 350523538 0
13
+ APPLE US 000000001 Acme Corp Widgets 1 1 .97 01/21/2010 01/21/2010 EUR IT EUR 350525324 1.59
14
+ APPLE US 000000000 Acme Corp Sprockets 1 34 0 01/21/2010 01/21/2010 EUR NL EUR 350523538 0
15
+ APPLE US 000000000 Acme Corp Sprockets 1 28 0 01/21/2010 01/21/2010 EUR ES EUR 350523538 0
16
+ APPLE US 000000000 Acme Corp Sprockets 1 20 0 01/21/2010 01/21/2010 SEK SE EUR 350523538 0
17
+ APPLE US 000000000 Acme Corp Sprockets 1 12 0 01/21/2010 01/21/2010 NOK NO EUR 350523538 0
18
+ APPLE US 000000000 Acme Corp Sprockets 1 45 0 01/21/2010 01/21/2010 CHF CH EUR 350523538 0
19
+ APPLE US 000000000 Acme Corp Sprockets 1 24 0 01/21/2010 01/21/2010 AUD AU AUD 350523538 0
20
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 USD TW USD 350523538 0
21
+ APPLE US 000000000 Acme Corp Sprockets 1 8 0 01/21/2010 01/21/2010 EUR PL EUR 350523538 0
22
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 EUR HU EUR 350523538 0
23
+ APPLE US 000000000 Acme Corp Sprockets 1 5 0 01/21/2010 01/21/2010 EUR CZ EUR 350523538 0
24
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 EUR SK EUR 350523538 0
25
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD AR USD 350523538 0
26
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 EUR FI EUR 350523538 0
27
+ APPLE US 000000000 Acme Corp Sprockets 1 41 0 01/21/2010 01/21/2010 JPY JP JPY 350523538 0
28
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD IN USD 350523538 0
29
+ APPLE US 000000000 Acme Corp Sprockets 1 7 0 01/21/2010 01/21/2010 MXN MX USD 350523538 0
30
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD TH USD 350523538 0
31
+ APPLE US 000000000 Acme Corp Sprockets 1 9 0 01/21/2010 01/21/2010 USD IL USD 350523538 0
32
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD LB USD 350523538 0
33
+ APPLE US 000000000 Acme Corp Sprockets 1 5 0 01/21/2010 01/21/2010 EUR AT EUR 350523538 0
34
+ APPLE US 000000001 Acme Corp Widgets 1 1 1.58 01/21/2010 01/21/2010 NZD NZ AUD 350525324 2.59
35
+ APPLE US 000000000 Acme Corp Sprockets 1 12 0 01/21/2010 01/21/2010 USD RU USD 350523538 0
36
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD PK USD 350523538 0
37
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD SA USD 350523538 0
38
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 USD HR USD 350523538 0
39
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/21/2010 01/21/2010 USD EG USD 350523538 0
40
+ APPLE US 000000001 Acme Corp Widgets 1 16 1.4 01/21/2010 01/21/2010 USD US USD 350525324 1.99
41
+ APPLE US 000000001 Acme Corp Widgets 1 3 .72 01/21/2010 01/21/2010 GBP GB GBP 350525324 1.19
42
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 EUR PT EUR 350523538 0
43
+ APPLE US 000000000 Acme Corp Sprockets 1 208 0 01/21/2010 01/21/2010 CAD CA CAD 350523538 0
44
+ APPLE US 000000000 Acme Corp Sprockets 1 15 0 01/21/2010 01/21/2010 DKK DK EUR 350523538 0
45
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/21/2010 01/21/2010 NZD NZ AUD 350523538 0
46
+ APPLE US 000000000 Acme Corp Sprockets 1 204 0 01/21/2010 01/21/2010 GBP GB GBP 350523538 0
47
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 EUR IE EUR 350523538 0
48
+ APPLE US 000000000 Acme Corp Sprockets 1 104 0 01/21/2010 01/21/2010 EUR IT EUR 350523538 0
49
+ APPLE US 000000000 Acme Corp Sprockets 1 11 0 01/21/2010 01/21/2010 USD SG USD 350523538 0
50
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/21/2010 01/21/2010 USD KW USD 350523538 0
51
+ APPLE US 000000000 Acme Corp Sprockets 1 230 0 01/21/2010 01/21/2010 EUR FR EUR 350523538 0
52
+ APPLE US 000000000 Acme Corp Sprockets 1 8 0 01/21/2010 01/21/2010 EUR BE EUR 350523538 0
53
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/21/2010 01/21/2010 EUR GR EUR 350523538 0
54
+ APPLE US 000000000 Acme Corp Sprockets 1 9 0 01/21/2010 01/21/2010 USD TR USD 350523538 0
@@ -0,0 +1,56 @@
1
+ Provider Provider Country Vendor Identifier UPC ISRC Artist / Show Title / Episode / Season Label/Studio/Network Product Type Identifier Units Royalty Price Begin Date End Date Customer Currency Country Code Royalty Currency Preorder Season Pass ISAN Apple Identifier Customer Price CMA Asset/Content Flavor Vendor Offer Code Grid Promo Code Parent Identifier
2
+ APPLE US 000000000 Acme Corp Sprockets 1 205 0 01/23/2010 01/23/2010 USD US USD 350523538 0
3
+ APPLE US 000000001 Acme Corp Widgets 1 4 .36 01/23/2010 01/23/2010 GBP GB GBP 350525324 .59
4
+ APPLE US 000000000 Acme Corp Sprockets 1 82 0 01/23/2010 01/23/2010 EUR IT EUR 350523538 0
5
+ APPLE US 000000000 Acme Corp Sprockets 1 153 0 01/23/2010 01/23/2010 CAD CA CAD 350523538 0
6
+ APPLE US 000000001 Acme Corp Widgets 1 1 .97 01/23/2010 01/23/2010 EUR FR EUR 350525324 1.59
7
+ APPLE US 000000001 Acme Corp Widgets 1 2 .97 01/23/2010 01/23/2010 EUR DE EUR 350525324 1.59
8
+ APPLE US 000000000 Acme Corp Sprockets 1 63 0 01/23/2010 01/23/2010 EUR DE EUR 350523538 0
9
+ APPLE US 000000001 Acme Corp Widgets 1 3 .72 01/23/2010 01/23/2010 GBP GB GBP 350525324 1.19
10
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/23/2010 01/23/2010 EUR PT EUR 350523538 0
11
+ APPLE US 000000001 Acme Corp Widgets 1 8 .7 01/23/2010 01/23/2010 CAD CA CAD 350525324 .99
12
+ APPLE US 000000001 Acme Corp Widgets 1 2 1.4 01/23/2010 01/23/2010 CAD CA CAD 350525324 1.99
13
+ APPLE US 000000001 Acme Corp Widgets 1 1 .97 01/23/2010 01/23/2010 NOK NO EUR 350525324 11
14
+ APPLE US 000000000 Acme Corp Sprockets 1 43 0 01/23/2010 01/23/2010 JPY JP JPY 350523538 0
15
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/23/2010 01/23/2010 USD ID USD 350523538 0
16
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/23/2010 01/23/2010 USD TR USD 350523538 0
17
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/23/2010 01/23/2010 EUR CZ EUR 350523538 0
18
+ APPLE US 000000001 Acme Corp Widgets 1 28 .7 01/23/2010 01/23/2010 USD US USD 350525324 .99
19
+ APPLE US 000000000 Acme Corp Sprockets 1 15 0 01/23/2010 01/23/2010 EUR NL EUR 350523538 0
20
+ APPLE US 000000001 Acme Corp Widgets 1 1 .48 01/23/2010 01/23/2010 EUR ES EUR 350525324 .79
21
+ APPLE US 000000000 Acme Corp Sprockets 1 14 0 01/23/2010 01/23/2010 SEK SE EUR 350523538 0
22
+ APPLE US 000000001 Acme Corp Widgets 1 1 .97 01/23/2010 01/23/2010 CHF CH EUR 350525324 2.2
23
+ APPLE US 000000000 Acme Corp Sprockets 1 4 0 01/23/2010 01/23/2010 USD SG USD 350523538 0
24
+ APPLE US 000000000 Acme Corp Sprockets 1 4 0 01/23/2010 01/23/2010 USD TH USD 350523538 0
25
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/23/2010 01/23/2010 EUR GR EUR 350523538 0
26
+ APPLE US 000000000 Acme Corp Sprockets 1 10 0 01/23/2010 01/23/2010 EUR ES EUR 350523538 0
27
+ APPLE US 000000000 Acme Corp Sprockets 1 4 0 01/23/2010 01/23/2010 EUR PL EUR 350523538 0
28
+ APPLE US 000000000 Acme Corp Sprockets 1 8 0 01/23/2010 01/23/2010 EUR AT EUR 350523538 0
29
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/23/2010 01/23/2010 EUR BE EUR 350523538 0
30
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/23/2010 01/23/2010 EUR LU EUR 350523538 0
31
+ APPLE US 000000000 Acme Corp Sprockets 1 41 0 01/23/2010 01/23/2010 CHF CH EUR 350523538 0
32
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/23/2010 01/23/2010 NZD NZ AUD 350523538 0
33
+ APPLE US 000000000 Acme Corp Sprockets 1 114 0 01/23/2010 01/23/2010 EUR FR EUR 350523538 0
34
+ APPLE US 000000001 Acme Corp Widgets 1 3 .48 01/23/2010 01/23/2010 EUR FR EUR 350525324 .79
35
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/23/2010 01/23/2010 EUR IE EUR 350523538 0
36
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/23/2010 01/23/2010 USD TW USD 350523538 0
37
+ APPLE US 000000000 Acme Corp Sprockets 1 2 0 01/23/2010 01/23/2010 USD IL USD 350523538 0
38
+ APPLE US 000000001 Acme Corp Widgets 1 1 .97 01/23/2010 01/23/2010 EUR BE EUR 350525324 1.59
39
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/23/2010 01/23/2010 EUR FI EUR 350523538 0
40
+ APPLE US 000000001 Acme Corp Widgets 1 1 .48 01/23/2010 01/23/2010 EUR NL EUR 350525324 .79
41
+ APPLE US 000000001 Acme Corp Widgets 1 1 .97 01/23/2010 01/23/2010 EUR NL EUR 350525324 1.59
42
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/23/2010 01/23/2010 DKK DK EUR 350523538 0
43
+ APPLE US 000000000 Acme Corp Sprockets 1 9 0 01/23/2010 01/23/2010 AUD AU AUD 350523538 0
44
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/23/2010 01/23/2010 USD HK USD 350523538 0
45
+ APPLE US 000000000 Acme Corp Sprockets 1 6 0 01/23/2010 01/23/2010 USD CN USD 350523538 0
46
+ APPLE US 000000000 Acme Corp Sprockets 1 3 0 01/23/2010 01/23/2010 MXN MX USD 350523538 0
47
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/23/2010 01/23/2010 USD LB USD 350523538 0
48
+ APPLE US 000000001 Acme Corp Widgets 1 5 1.4 01/23/2010 01/23/2010 USD US USD 350525324 1.99
49
+ APPLE US 000000000 Acme Corp Sprockets 1 124 0 01/23/2010 01/23/2010 GBP GB GBP 350523538 0
50
+ APPLE US 000000001 Acme Corp Widgets 1 1 .48 01/23/2010 01/23/2010 EUR BE EUR 350525324 .79
51
+ APPLE US 000000000 Acme Corp Sprockets 1 8 0 01/23/2010 01/23/2010 NOK NO EUR 350523538 0
52
+ APPLE US 000000000 Acme Corp Sprockets 1 4 0 01/23/2010 01/23/2010 USD IN USD 350523538 0
53
+ APPLE US 000000001 Acme Corp Widgets 1 1 1.4 01/23/2010 01/23/2010 USD RU USD 350525324 1.99
54
+ APPLE US 000000000 Acme Corp Sprockets 1 7 0 01/23/2010 01/23/2010 USD RU USD 350523538 0
55
+ APPLE US 000000000 Acme Corp Sprockets 1 1 0 01/23/2010 01/23/2010 EUR HU EUR 350523538 0
56
+ APPLE US 000000001 Acme Corp Widgets 1 1 .7 01/23/2010 01/23/2010 USD CO USD 350525324 .99
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Parser do
4
+ before(:each) do
5
+ @good_files = [FIXTURES_DIR + '/uploads/demo1.txt', FIXTURES_DIR + '/uploads/demo2.txt']
6
+ @bad_file = FIXTURES_DIR + '/uploads/bad_demo1.txt'
7
+ @no_file = '!'
8
+
9
+ @count_good_files = [53, 55]
10
+ end
11
+
12
+ describe "when created" do
13
+ it "should handle empty array of files" do
14
+ @parser = Parser.new []
15
+ @parser.transactions.count.should == 0
16
+ end
17
+
18
+ it "should be able to open file" do
19
+ @parser = Parser.new @good_files[0]
20
+ @parser.transactions.count.should == @count_good_files[0]
21
+ end
22
+
23
+ it "should be able to open multiple files" do
24
+ @parser = Parser.new @good_files
25
+ @parser.transactions.count.should == @count_good_files[0] + @count_good_files[1]
26
+ end
27
+
28
+ it "should return error when file does not exist" do
29
+ lambda{ Parser.new(@no_file) }.should raise_error(Errno::ENOENT)
30
+ end
31
+
32
+ it "should return error when file is badly formed" do
33
+ lambda{ Parser.new(@bad_file) }.should raise_error(WrongNumberOfElements)
34
+ end
35
+ end
36
+
37
+ describe "when adding files" do
38
+ before(:each) do
39
+ @parser = Parser.new
40
+ end
41
+
42
+ it "should be able to add single file" do
43
+ @parser.add_file @good_files[0]
44
+ @parser.transactions.count.should == @count_good_files[0]
45
+ end
46
+
47
+ it "should be able to add multiple files" do
48
+ @parser.add_files @good_files
49
+ @parser.transactions.count.should == @count_good_files[0] + @count_good_files[1]
50
+ end
51
+ end
52
+
53
+ describe "when adding transaction" do
54
+ before(:each) do
55
+ @parser = Parser.new
56
+ @good_transaction = "APPLE US 000000001 Acme Corp Widgets 1 1 0 1/21/10 1/21/10 USD US USD 350525324 0 CR-RW "
57
+ @bad_transaction = "APPLE US 000000001 Acme Corp Widgets 1 1 0 1/21/10 1/21/10 USD US USD"
58
+ end
59
+
60
+ it "should handle correctly formed transaction" do
61
+ @parser.add_transaction @good_transaction
62
+ @parser.transactions.count.should == 1
63
+ end
64
+
65
+ it "should handle incorrectly formed transaction" do
66
+ lambda { @parser.add_transaction @bad_transaction }.should raise_error(WrongNumberOfElements)
67
+ end
68
+ end
69
+
70
+ describe "when counting transactions" do
71
+ before(:each) do
72
+ @parser = Parser.new @good_files[0]
73
+ end
74
+
75
+ it "should handle correctly formed transaction" do
76
+ @parser.transactions.count.should == @count_good_files[0]
77
+ end
78
+ end
79
+ end
data/spec/rcov.opts ADDED
@@ -0,0 +1 @@
1
+ --exclude "spec/*"
data/spec/spec.opts ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --format progress
3
+ --loadby mtime
4
+ --reverse
5
+ --drb
@@ -0,0 +1,5 @@
1
+ require 'spec/autorun'
2
+ require 'lib/parseitc'
3
+ include ParseITC
4
+
5
+ FIXTURES_DIR = "#{File.dirname(__FILE__)}/fixtures"
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Transaction do
4
+ before(:each) do
5
+ @good_transaction = "APPLE US 000000001 Acme Corp Widgets 1 2 1.4 01/21/2010 01/21/2010 CAD CA CAD 350525324 1.99 ".split(/\t/)
6
+ @free_transaction = "APPLE US 000000000 Acme Corp Sprockets 1 13 0 01/21/2010 01/21/2010 USD HK USD 350523538 0 ".split(/\t/)
7
+ # not enough tabs
8
+ @malformed_transaction = "APPLE US 000000001 Acme Corp Widgets 1 1 0 1/21/10 1/21/10 USD US USD".split(/\t/)
9
+ # price tier does not match
10
+ @badly_priced_transaction = "APPLE US 000000001 Acme Corp Widgets 1 2 1.2 01/21/2010 01/21/2010 CAD CA CAD 350525324 1.19 ".split(/\t/)
11
+ end
12
+
13
+ it "should load good transactions" do
14
+ xion = Transaction.new @good_transaction
15
+ xion.price_tier.should == 2
16
+
17
+ xion = Transaction.new @free_transaction
18
+ xion.price_tier.should == 0
19
+ end
20
+
21
+ it "should raise error on malformed transaction" do
22
+ lambda { Transaction.new @malformed_transaction }.should raise_error(WrongNumberOfElements)
23
+ end
24
+
25
+ it "should raise error on badly priced transaction" do
26
+ lambda { Transaction.new @badly_priced_transaction }.should raise_error(PriceTierNotFound)
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parseitc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - HJ Choi
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-02 00:00:00 -08:00
12
+ date: 2010-02-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,16 @@ files:
29
29
  - demo1.txt
30
30
  - demo2.txt
31
31
  - lib/parseitc.rb
32
+ - lib/parseitc/parser.rb
33
+ - lib/parseitc/transaction.rb
34
+ - spec/rcov.opts
35
+ - spec/spec.opts
36
+ - spec/spec_helper.rb
37
+ - spec/parser_spec.rb
38
+ - spec/transaction_spec.rb
39
+ - spec/fixtures/uploads/bad_demo1.txt
40
+ - spec/fixtures/uploads/demo1.txt
41
+ - spec/fixtures/uploads/demo2.txt
32
42
  has_rdoc: true
33
43
  homepage: http://www.choibean.com/parseitc
34
44
  licenses: []