Class: SepaFileParser::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/sepa_file_parser/general/record.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_data) ⇒ Record

Returns a new instance of Record.



8
9
10
11
# File 'lib/sepa_file_parser/general/record.rb', line 8

def initialize(xml_data)
  @xml_data = xml_data
  @amount = xml_data.xpath('Amt/text()').text
end

Instance Attribute Details

#xml_dataObject (readonly)

Returns the value of attribute xml_data.



6
7
8
# File 'lib/sepa_file_parser/general/record.rb', line 6

def xml_data
  @xml_data
end

Instance Method Details

#amountObject



13
14
15
# File 'lib/sepa_file_parser/general/record.rb', line 13

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

#amount_in_centsObject



17
18
19
# File 'lib/sepa_file_parser/general/record.rb', line 17

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

#charges_included?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/sepa_file_parser/general/record.rb', line 29

def charges_included?
  @charges_included ||= xml_data.xpath('ChrgInclInd/text()').text.downcase == 'true'
end

#credit?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/sepa_file_parser/general/record.rb', line 37

def credit?
  !debit
end

#currencyObject



21
22
23
# File 'lib/sepa_file_parser/general/record.rb', line 21

def currency
  @currency ||= xml_data.xpath('Amt/@Ccy').text
end

#debitObject



33
34
35
# File 'lib/sepa_file_parser/general/record.rb', line 33

def debit
  @debit ||= xml_data.xpath('CdtDbtInd/text()').text.upcase == 'DBIT'
end

#debit?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/sepa_file_parser/general/record.rb', line 41

def debit?
  debit
end

#signObject



45
46
47
# File 'lib/sepa_file_parser/general/record.rb', line 45

def sign
  credit? ? 1 : -1
end

#typeObject



25
26
27
# File 'lib/sepa_file_parser/general/record.rb', line 25

def type
  @type ||= SepaFileParser::Type::Builder.build_type(xml_data.xpath('Tp'))
end