Class: Qif::Reader
Overview
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Call a block with each Qif::Transaction from the Qif file.
-
#initialize(data, format = 'dd/mm/yyyy') ⇒ Reader
constructor
Create a new Qif::Reader object.
-
#size ⇒ Object
(also: #length)
Return the number of transactions in the qif file.
-
#transactions ⇒ Object
Return an array of Qif::Transaction objects from the Qif file.
Constructor Details
#initialize(data, format = 'dd/mm/yyyy') ⇒ Reader
Create a new Qif::Reader object. The data argument must be either an IO object or a String containing the Qif file data.
The format argument specifies the date format in the file. This defaults to 'dd/mm/yyyy', but also accepts 'mm/dd/yyyy'.
24 25 26 27 28 29 |
# File 'lib/qif/reader.rb', line 24 def initialize(data, format = 'dd/mm/yyyy') @format = DateFormat.new(format) @data = data.respond_to?(:read) ? data : StringIO.new(data.to_s) read_header reset end |
Instance Method Details
#each(&block) ⇒ Object
Call a block with each Qif::Transaction from the Qif file. This method yields each transaction as it reads the file so it is better to use this than #transactions for large qif files.
reader.each do |transaction|
puts transaction.amount
end
46 47 48 49 50 51 52 |
# File 'lib/qif/reader.rb', line 46 def each(&block) reset while transaction = next_transaction yield transaction end end |
#size ⇒ Object Also known as: length
Return the number of transactions in the qif file.
55 56 57 58 |
# File 'lib/qif/reader.rb', line 55 def size read_all_transactions transaction_cache.size end |
#transactions ⇒ Object
Return an array of Qif::Transaction objects from the Qif file. This method reads the whole file before returning, so it may not be suitable for very large qif files.
34 35 36 37 |
# File 'lib/qif/reader.rb', line 34 def transactions read_all_transactions transaction_cache end |