Class: ParseITC::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/parseitc/transaction.rb

Constant Summary collapse

YEAR_TWO_THOUSAND =
Date.parse("1/1/2000")
TWO_THOUSAND_YEARS =
YEAR_TWO_THOUSAND - Date.parse("1/1/0")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Transaction

Returns a new instance of Transaction.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/parseitc/transaction.rb', line 25

def initialize array
  raise WrongNumberOfElements.new(27, array.length) unless array.length == 27
  @provider           = array[0]
  @provider_country   = array[1]
  @company            = array[5]
  @product            = array[6]
  @vendor_identifier  = array[2]
  @date               = Date.parse(array[11])
  @product_type_id    = array[8] # 1 = new, 7 = update
  @units              = array[9]
  @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
  raise PriceTierNotFound.new(royalty_price, royalty_currency) unless price_tier
end

Instance Attribute Details

#apple_identifierObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def apple_identifier
  @apple_identifier
end

#companyObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def company
  @company
end

#countryObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def country
  @country
end

#customer_currencyObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def customer_currency
  @customer_currency
end

#customer_priceObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def customer_price
  @customer_price
end

#dateObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def date
  @date
end

#productObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def product
  @product
end

#promo_codeObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def promo_code
  @promo_code
end

#providerObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def provider
  @provider
end

#provider_countryObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def provider_country
  @provider_country
end

#royalty_currencyObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def royalty_currency
  @royalty_currency
end

#royalty_priceObject Also known as: price

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def royalty_price
  @royalty_price
end

#unitsObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def units
  @units
end

#vendor_identifierObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def vendor_identifier
  @vendor_identifier
end

#vendor_offer_codeObject

ignoring some columns that are ignored by iphone apps



7
8
9
# File 'lib/parseitc/transaction.rb', line 7

def vendor_offer_code
  @vendor_offer_code
end

Instance Method Details

#has_field?(field) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/parseitc/transaction.rb', line 62

def has_field? field
  (instance_variables.map{|variable| variable[1..-1]} + public_methods).include? field
end

#price_tierObject



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/parseitc/transaction.rb', line 49

def price_tier
  @price_tier ||= begin
    prices = ApplePricing[@royalty_currency.downcase.to_sym]
    if @customer_price.to_f == 0
      0
    else
      prices.find_index(@royalty_price.to_f)
    end
  rescue
    nil
  end
end