Class: CamtParser::Transaction

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

Instance Method Summary collapse

Constructor Details

#initialize(xml_data, debit, amount = nil, currency = nil) ⇒ Transaction

Returns a new instance of Transaction.


3
4
5
6
7
8
# File 'lib/camt_parser/general/transaction.rb', line 3

def initialize(xml_data, debit, amount = nil, currency = nil)
  @xml_data = xml_data
  @debit    = debit
  @amount   = parse_amount || amount
  @currency = parse_currency || currency
end

Instance Method Details

#additional_informationObject

May be missing


104
105
106
# File 'lib/camt_parser/general/transaction.rb', line 104

def additional_information # May be missing
  @addition_information ||= @xml_data.xpath('AddtlTxInf/text()').text
end

#amountObject


10
11
12
# File 'lib/camt_parser/general/transaction.rb', line 10

def amount
  CamtParser::Misc.to_amount(@amount)
end

#amount_in_centsObject


14
15
16
# File 'lib/camt_parser/general/transaction.rb', line 14

def amount_in_cents
  CamtParser::Misc.to_amount_in_cents(@amount)
end

#bank_referenceObject

May be missing


76
77
78
# File 'lib/camt_parser/general/transaction.rb', line 76

def bank_reference # May be missing
  @bank_reference ||= @xml_data.xpath('Refs/AcctSvcrRef/text()').text
end

#bicObject


38
39
40
# File 'lib/camt_parser/general/transaction.rb', line 38

def bic
  credit? ? debitor.bic : creditor.bic
end

#credit?Boolean

Returns:

  • (Boolean)

42
43
44
# File 'lib/camt_parser/general/transaction.rb', line 42

def credit?
  !debit
end

#creditorObject


22
23
24
# File 'lib/camt_parser/general/transaction.rb', line 22

def creditor
  @creditor ||= CamtParser::Creditor.new(@xml_data)
end

#creditor_identifierObject

May be missing


96
97
98
# File 'lib/camt_parser/general/transaction.rb', line 96

def creditor_identifier # May be missing
  @creditor_identifier ||= @xml_data.xpath('RltdPties/Cdtr/Id/PrvtId/Othr/Id/text()').text
end

#creditor_referenceObject

May be missing


88
89
90
# File 'lib/camt_parser/general/transaction.rb', line 88

def creditor_reference # May be missing
  @creditor_reference ||= @xml_data.xpath('RmtInf/Strd/CdtrRefInf/Ref/text()').text
end

#currencyObject


18
19
20
# File 'lib/camt_parser/general/transaction.rb', line 18

def currency
  @currency
end

#debitObject


50
51
52
# File 'lib/camt_parser/general/transaction.rb', line 50

def debit
  @debit
end

#debit?Boolean

Returns:

  • (Boolean)

46
47
48
# File 'lib/camt_parser/general/transaction.rb', line 46

def debit?
  debit
end

#debitorObject


26
27
28
# File 'lib/camt_parser/general/transaction.rb', line 26

def debitor
  @debitor ||= CamtParser::Debitor.new(@xml_data)
end

#end_to_end_referenceObject

May be missing


80
81
82
# File 'lib/camt_parser/general/transaction.rb', line 80

def end_to_end_reference # May be missing
  @end_to_end_reference ||= @xml_data.xpath('Refs/EndToEndId/text()').text
end

#ibanObject


34
35
36
# File 'lib/camt_parser/general/transaction.rb', line 34

def iban
  credit? ? debitor.iban : creditor.iban
end

#mandate_referenceObject

May be missing


84
85
86
# File 'lib/camt_parser/general/transaction.rb', line 84

def mandate_reference # May be missing
  @mandate_reference ||= @xml_data.xpath('Refs/MndtId/text()').text
end

#nameObject


30
31
32
# File 'lib/camt_parser/general/transaction.rb', line 30

def name
  credit? ? debitor.name : creditor.name
end

#payment_informationObject

May be missing


100
101
102
# File 'lib/camt_parser/general/transaction.rb', line 100

def payment_information # May be missing
  @payment_information ||= @xml_data.xpath('Refs/PmtInfId/text()').text
end

#reason_codeObject

May be missing


108
109
110
# File 'lib/camt_parser/general/transaction.rb', line 108

def reason_code # May be missing
  @reason_code ||= @xml_data.xpath('RtrInf/Rsn/Cd/text()').text
end

#referenceObject


72
73
74
# File 'lib/camt_parser/general/transaction.rb', line 72

def reference
  @reference ||= @xml_data.xpath('Refs/InstrId/text()').text
end

#remittance_informationObject


58
59
60
61
62
63
64
65
66
# File 'lib/camt_parser/general/transaction.rb', line 58

def remittance_information
  @remittance_information ||= begin
    if (x = @xml_data.xpath('RmtInf/Ustrd')).empty?
      nil
    else
      x.collect(&:content).join(' ')
    end
  end
end

#signObject


54
55
56
# File 'lib/camt_parser/general/transaction.rb', line 54

def sign
  credit? ? 1 : -1
end

#swift_codeObject


68
69
70
# File 'lib/camt_parser/general/transaction.rb', line 68

def swift_code
  @swift_code ||= @xml_data.xpath('BkTxCd/Prtry/Cd/text()').text.split('+')[0]
end

#transaction_idObject

May be missing


92
93
94
# File 'lib/camt_parser/general/transaction.rb', line 92

def transaction_id # May be missing
  @transaction_id ||= @xml_data.xpath('Refs/TxId/text()').text
end