Class: CamtParser::Format053::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/camt_parser/053/statement.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_data) ⇒ Statement

Returns a new instance of Statement.



7
8
9
# File 'lib/camt_parser/053/statement.rb', line 7

def initialize(xml_data)
  @xml_data = xml_data
end

Instance Attribute Details

#xml_dataObject (readonly)

Returns the value of attribute xml_data.



5
6
7
# File 'lib/camt_parser/053/statement.rb', line 5

def xml_data
  @xml_data
end

Class Method Details

.parse(xml) ⇒ Object



68
69
70
# File 'lib/camt_parser/053/statement.rb', line 68

def self.parse(xml)
  self.new Nokogiri::XML(xml).xpath('Stmt')
end

Instance Method Details

#accountObject



27
28
29
# File 'lib/camt_parser/053/statement.rb', line 27

def 
  @account ||= Account.new(xml_data.xpath('Acct').first)
end

#closing_balanceObject Also known as: closing_or_intermediary_balance



53
54
55
56
57
58
59
60
61
# File 'lib/camt_parser/053/statement.rb', line 53

def closing_balance
  @closing_balance ||= begin
    bal = xml_data.xpath('Bal/Tp//Cd[contains(text(), "CLBD")]').first.ancestors('Bal')
    date = bal.xpath('Dt/Dt/text()').text
    credit = bal.xpath('CdtDbtInd/text()').text == 'CRDT'
    currency = bal.xpath('Amt').attribute('Ccy').value
    AccountBalance.new bal.xpath('Amt/text()').text, currency, date, credit
  end
end

#electronic_sequence_numberObject



39
40
41
# File 'lib/camt_parser/053/statement.rb', line 39

def electronic_sequence_number
  @electronic_sequence_number ||= xml_data.xpath('ElctrncSeqNb/text()').text
end

#entriesObject



31
32
33
# File 'lib/camt_parser/053/statement.rb', line 31

def entries
  @entries ||= xml_data.xpath('Ntry').map{ |x| Entry.new(x) }
end

#from_date_timeObject



19
20
21
# File 'lib/camt_parser/053/statement.rb', line 19

def from_date_time
  @from_date_time ||= (x = xml_data.xpath('FrToDt/FrDtTm')).empty? ? nil : Time.parse(x.first.content)
end

#generation_dateObject



15
16
17
# File 'lib/camt_parser/053/statement.rb', line 15

def generation_date
  @generation_date ||= Time.parse(xml_data.xpath('CreDtTm/text()').text)
end

#identificationObject



11
12
13
# File 'lib/camt_parser/053/statement.rb', line 11

def identification
  @identification ||= xml_data.xpath('Id/text()').text
end


35
36
37
# File 'lib/camt_parser/053/statement.rb', line 35

def legal_sequence_number
  @legal_sequence_number ||= xml_data.xpath('LglSeqNb/text()').text
end

#opening_balanceObject



43
44
45
46
47
48
49
50
51
# File 'lib/camt_parser/053/statement.rb', line 43

def opening_balance
  @opening_balance ||= begin
    bal = xml_data.xpath('Bal/Tp//Cd[contains(text(), "OPBD") or contains(text(), "PRCD")]').first.ancestors('Bal')
    date = bal.xpath('Dt/Dt/text()').text
    credit = bal.xpath('CdtDbtInd/text()').text == 'CRDT'
    currency = bal.xpath('Amt').attribute('Ccy').value
    AccountBalance.new bal.xpath('Amt/text()').text, currency, date, credit
  end
end

#sourceObject



64
65
66
# File 'lib/camt_parser/053/statement.rb', line 64

def source
  xml_data.to_s
end

#to_date_timeObject



23
24
25
# File 'lib/camt_parser/053/statement.rb', line 23

def to_date_time
  @to_date_time ||= (x = xml_data.xpath('FrToDt/ToDtTm')).empty? ? nil : Time.parse(x.first.content)
end