Class: SepaFileParser::Camt052::Report
- Inherits:
-
Object
- Object
- SepaFileParser::Camt052::Report
- Defined in:
- lib/sepa_file_parser/camt052/report.rb
Instance Attribute Summary collapse
-
#xml_data ⇒ Object
readonly
Returns the value of attribute xml_data.
Class Method Summary collapse
Instance Method Summary collapse
- #account ⇒ Object
- #closing_balance ⇒ Object (also: #closing_or_intermediary_balance)
- #entries ⇒ Object
- #from_date_time ⇒ Object
- #generation_date ⇒ Object
- #identification ⇒ Object
-
#initialize(xml_data) ⇒ Report
constructor
A new instance of Report.
- #legal_sequence_number ⇒ Object
- #opening_balance ⇒ Object (also: #opening_or_intermediary_balance)
- #source ⇒ Object
- #to_date_time ⇒ Object
Constructor Details
#initialize(xml_data) ⇒ Report
Returns a new instance of Report.
9 10 11 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 9 def initialize(xml_data) @xml_data = xml_data end |
Instance Attribute Details
#xml_data ⇒ Object (readonly)
Returns the value of attribute xml_data.
7 8 9 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 7 def xml_data @xml_data end |
Class Method Details
.parse(xml) ⇒ Object
71 72 73 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 71 def self.parse(xml) self.new Nokogiri::XML(xml).xpath('Report') end |
Instance Method Details
#account ⇒ Object
21 22 23 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 21 def account @account ||= SepaFileParser::Account.from_camt_data(xml_data.xpath('Acct').first) end |
#closing_balance ⇒ Object Also known as: closing_or_intermediary_balance
55 56 57 58 59 60 61 62 63 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 55 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 SepaFileParser::AccountBalance.new bal.xpath('Amt/text()').text, currency, date, credit end end |
#entries ⇒ Object
25 26 27 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 25 def entries @entries ||= xml_data.xpath('Ntry').map{ |x| SepaFileParser::Entry.new(x) } end |
#from_date_time ⇒ Object
33 34 35 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 33 def from_date_time @from_date_time ||= (x = xml_data.xpath('FrToDt/FrDtTm')).empty? ? nil : Time.parse(x.first.content) end |
#generation_date ⇒ Object
17 18 19 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 17 def generation_date @generation_date ||= Time.parse(xml_data.xpath('CreDtTm/text()').text) end |
#identification ⇒ Object
13 14 15 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 13 def identification @identification ||= xml_data.xpath('Id/text()').text end |
#legal_sequence_number ⇒ Object
29 30 31 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 29 def legal_sequence_number @legal_sequence_number ||= xml_data.xpath('LglSeqNb/text()').text end |
#opening_balance ⇒ Object Also known as: opening_or_intermediary_balance
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 41 def opening_balance @opening_balance ||= begin openingNode = xml_data.xpath('Bal/Tp//Cd[contains(text(), "PRCD")]').first || xml_data.xpath('Bal/Tp//Cd[contains(text(), "OPBD")]').first bal = openingNode.ancestors('Bal') date = bal.xpath('Dt/Dt/text()').text credit = bal.xpath('CdtDbtInd/text()').text == 'CRDT' currency = bal.xpath('Amt').attribute('Ccy').value SepaFileParser::AccountBalance.new bal.xpath('Amt/text()').text, currency, date, credit end end |
#source ⇒ Object
67 68 69 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 67 def source xml_data.to_s end |
#to_date_time ⇒ Object
37 38 39 |
# File 'lib/sepa_file_parser/camt052/report.rb', line 37 def to_date_time @to_date_time ||= (x = xml_data.xpath('FrToDt/ToDtTm')).empty? ? nil : Time.parse(x.first.content) end |