Class: Amex::Transaction

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transaction) ⇒ Amex::Transaction

Generates an Amex::LoyaltyProgramme object from a Nokogiri object representing <Transaction> element

Parameters:

  • transaction (Nokogiri::XML::Element)

    A <Transaction> node taken the API XML request, parsed by Nokogiri



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/amex/transaction.rb', line 15

def initialize(transaction)
  # Pass this a <Transaction> element, and it'll parse it
  @date = Date.strptime(transaction.css('TransChargeDate').text, '%m/%d/%y')
  @narrative = transaction.css('TransDesc').text
  @amount = transaction.css('TransAmount').text.to_f

  @extra_details = {}
  transaction.css('TransExtDetail ExtDetailElement').each do |element|
    @extra_details[element.attr('name')] = element.attr('formattedValue')
  end
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/amex/transaction.rb', line 5

def amount
  @amount
end

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/amex/transaction.rb', line 5

def date
  @date
end

#extra_detailsObject (readonly)

Returns the value of attribute extra_details.



5
6
7
# File 'lib/amex/transaction.rb', line 5

def extra_details
  @extra_details
end

#narrativeObject (readonly)

Returns the value of attribute narrative.



5
6
7
# File 'lib/amex/transaction.rb', line 5

def narrative
  @narrative
end

Instance Method Details

#is_foreign_transaction?Boolean

Returns whether the transaction was made abroad/in a foreign currency

Returns:

  • (Boolean)

    true if the transaction was made abroad/in a foreign currency, false otherwise



32
33
34
35
# File 'lib/amex/transaction.rb', line 32

def is_foreign_transaction?
  return true if @extra_details.has_key?('currencyRate')
  false
end