class CamtParser::Entry

Attributes

xml_data[R]

Public Class Methods

new(xml_data) click to toggle source
# File lib/camt_parser/general/entry.rb, line 6
def initialize(xml_data)
  @xml_data = xml_data
  @amount = xml_data.xpath('Amt/text()').text
end

Public Instance Methods

additional_information() click to toggle source

@return [String]

# File lib/camt_parser/general/entry.rb, line 85
def additional_information
  @additional_information ||= xml_data.xpath('AddtlNtryInf/text()').text
end
Also aliased as: description
amount() click to toggle source
# File lib/camt_parser/general/entry.rb, line 11
def amount
  CamtParser::Misc.to_amount(@amount)
end
amount_in_cents() click to toggle source
# File lib/camt_parser/general/entry.rb, line 15
def amount_in_cents
  CamtParser::Misc.to_amount_in_cents(@amount)
end
bank_reference() click to toggle source

@return [String]

# File lib/camt_parser/general/entry.rb, line 50
def bank_reference # May be missing
  @bank_reference ||= xml_data.xpath('AcctSvcrRef/text()').text
end
batch_detail() click to toggle source

@return [CamtParser::BatchDetail, nil]

# File lib/camt_parser/general/entry.rb, line 95
def batch_detail
  @batch_detail ||= xml_data.xpath('NtryDtls/Btch').empty? ? nil : CamtParser::BatchDetail.new(@xml_data.xpath('NtryDtls/Btch'))
end
booked?() click to toggle source

@return [Boolean]

# File lib/camt_parser/general/entry.rb, line 80
def booked?
  @booked ||= xml_data.xpath('Sts/text()').text.upcase == 'BOOK'
end
booking_date() click to toggle source

@return [Date]

# File lib/camt_parser/general/entry.rb, line 35
def booking_date
  @booking_date ||= ((date = xml_data.xpath('BookgDt/Dt/text()').text).empty? ? nil : Date.parse(date))
end
booking_datetime() click to toggle source

@return [DateTime]

# File lib/camt_parser/general/entry.rb, line 45
def booking_datetime
  @booking_datetime ||= ((datetime = xml_data.xpath('BookgDt/DtTm/text()').text).empty? ? nil : DateTime.parse(datetime))
end
charges() click to toggle source

@return [CamtParser::Charges]

# File lib/camt_parser/general/entry.rb, line 91
def charges
  @charges ||= CamtParser::Charges.new(xml_data.xpath('Chrgs'))
end
credit?() click to toggle source

@return [Boolean]

# File lib/camt_parser/general/entry.rb, line 60
def credit?
  !debit
end
currency() click to toggle source

@return [String]

# File lib/camt_parser/general/entry.rb, line 20
def currency
  @currency ||= xml_data.xpath('Amt/@Ccy').text
end
debit() click to toggle source

@return [Boolean]

# File lib/camt_parser/general/entry.rb, line 25
def debit
  @debit ||= xml_data.xpath('CdtDbtInd/text()').text.upcase == 'DBIT'
end
debit?() click to toggle source

@return [Boolean]

# File lib/camt_parser/general/entry.rb, line 65
def debit?
  debit
end
description()
reversal?() click to toggle source

@return [Boolean]

# File lib/camt_parser/general/entry.rb, line 75
def reversal?
  @reversal ||= xml_data.xpath('RvslInd/text()').text.downcase == 'true'
end
sign() click to toggle source

@return [Integer] either 1 or -1

# File lib/camt_parser/general/entry.rb, line 70
def sign
  credit? ? 1 : -1
end
transactions() click to toggle source

@return [Array<CamtParser::Transaction>]

# File lib/camt_parser/general/entry.rb, line 55
def transactions
  @transactions ||= parse_transactions
end
value_date() click to toggle source

@return [Date]

# File lib/camt_parser/general/entry.rb, line 30
def value_date
  @value_date ||= ((date = xml_data.xpath('ValDt/Dt/text()').text).empty? ? nil : Date.parse(date))
end
value_datetime() click to toggle source

@return [DateTime]

# File lib/camt_parser/general/entry.rb, line 40
def value_datetime
  @value_datetime ||= ((datetime = xml_data.xpath('ValDt/DtTm/text()').text).empty? ? nil : DateTime.parse(datetime))
end

Private Instance Methods

parse_transactions() click to toggle source
# File lib/camt_parser/general/entry.rb, line 101
def parse_transactions
  transaction_details = xml_data.xpath('NtryDtls/TxDtls')

  amt = nil
  ccy = nil

  if transaction_details.length == 1
    amt = xml_data.xpath('Amt/text()').text
    ccy = xml_data.xpath('Amt/@Ccy').text
  end

  xml_data.xpath('NtryDtls/TxDtls').map { |x| Transaction.new(x, debit?, amt, ccy) }
end