ruby-on-railsrubyrubygemsbank

Cannot get iban from camt_parser rails gem


I just installed the camt_parser gem (https://github.com/Barzahlen/camt_parser)

With the following test program, no way to get the iban out of the substructre "transactions" from the structure "entry" from the structure "statement"

I get the following error:

in `block (2 levels) in <main>': undefined method `iban' for #<Array:0x007f9003a2ce30> (NoMethodError)

In the code I see that this class has a field called iban

Here is the code

require 'camt_parser'
camt = CamtParser::File.parse 'myCamt.xml'
camt.statements.each do |statement|

    statement.entries.each do |entry|
     # Access individual entries/bank transfers
     puts entry.description
     puts entry.debit
     puts entry.transactions.iban
    end

end

Thanks a lot guys!


Solution

  • It should be entry.transactions[0].iban as per the documentation. Check the Transaction#iban method. And the spec how to extract iban.

    let(:transactions)   { ex_entry.transactions }
    let(:ex_transaction) { transactions[0] }
    
    # .......
    
    specify { expect(ex_transaction.iban).to eq("DE09300606010012345671") }
    

    You called the iban on the collection of Transaction instances, but it should be on the instance of Transaction.