Class: CamtParser::Format053::Statement

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_data) ⇒ Statement

Returns a new instance of Statement.


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

def initialize(xml_data)
  @xml_data = xml_data
end

Class Method Details

.parse(xml) ⇒ Object


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

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

Instance Method Details

#accountObject


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

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

#closing_balanceObject Also known as: closing_or_intermediary_balance


50
51
52
53
54
55
56
57
# File 'lib/camt_parser/053/statement.rb', line 50

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
    currency = bal.xpath('Amt').attribute('Ccy').value
    AccountBalance.new bal.xpath('Amt/text()').text, currency, date, true
  end
end

#electronic_sequence_numberObject


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

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

#entriesObject


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

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

#from_date_timeObject


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

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

#generation_dateObject


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

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

#identificationObject


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

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

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

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

#opening_balanceObject Also known as: opening_or_intermediary_balance


40
41
42
43
44
45
46
47
# File 'lib/camt_parser/053/statement.rb', line 40

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
    currency = bal.xpath('Amt').attribute('Ccy').value
    AccountBalance.new bal.xpath('Amt/text()').text, currency, date, true
  end
end

#sourceObject


60
61
62
# File 'lib/camt_parser/053/statement.rb', line 60

def source
  @xml_data.to_s
end

#to_date_timeObject


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

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