lib/parseitc.rb in parseitc-0.1 vs lib/parseitc.rb in parseitc-0.1.1
- old
+ new
@@ -1,13 +1,15 @@
#!/usr/bin/env ruby
module ParseITC
- class TrasactionParser
+ class TransactionParser
attr_accessor :transactions
Version = '0.1'
- def initialize(filename=nil)
+ # filenames can be either string or array
+ def initialize(filenames=[])
@transactions = []
- add_file filename if filename
+ filenames = [filenames].flatten
+ filenames.each{|f| add_file f} unless filenames.empty?
end
def add_file filename
lines = File.readlines(filename)
lines.shift if lines.first.match(/^Provider/)
@@ -58,37 +60,44 @@
:company, # company x
:product, # widgets and sprockets
:vendor_identifier, # id you give the product
:date, # just take the begin date
:units,
- :price,
+ :royalty_price, # this is what you get paid
:royalty_currency,
:customer_price,
:customer_currency,
+ :vendor_offer_code,
+ :promo_code,
:country,
:apple_identifier # itunes link id
+
+ alias :price :royalty_price
+
def initialize array
@provider = array[0]
@provider_country = array[1]
@company = array[5]
@product = array[6]
@vendor_identifier = array[2]
@date = Date.parse(array[11])
@units = array[9]
- @price = array[10]
+ @royalty_price = array[10]
@royalty_currency = array[15]
@customer_price = array[20]
@customer_currency = array[13]
+ @vendor_offer_code = array[23]
+ @promo_code = array[25]
@country = array[14]
@apple_identifier = array[19]
# Adjust date if necessary ("1/5/10" should not be 10 A.D.)
@date += TWO_THOUSAND_YEARS if @date < YEAR_TWO_THOUSAND
end
def price_tier
prices = ApplePricing[@royalty_currency.downcase.to_sym]
- prices.find_index(@price.to_f)
+ prices.find_index(@royalty_price.to_f)
end
end
class WrongNumberOfElementsException < Exception
def initialize(expected, actual)