Method: Qif::Reader#initialize

Defined in:
lib/qif/reader.rb

#initialize(data, format = nil) ⇒ 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 optional format argument specifies the date format in the file. Giving a format will force it, otherwise the format will guessed reading the transactions in the file, this defaults to ‘dd/mm/yyyy’ if guessing method fails.

Raises:



40
41
42
43
44
45
46
47
# File 'lib/qif/reader.rb', line 40

def initialize(data, format = nil)
  @data = data.respond_to?(:read) ? data : StringIO.new(data.to_s)
  @format = DateFormat.new(format || guess_date_format || 'dd/mm/yyyy')
  read_header
  raise(UnrecognizedData, "Provided data doesn't seems to represent a QIF file") unless @header
  raise(UnknownAccountType, "Unknown account type. Should be one of followings :\n#{SUPPORTED_ACCOUNTS.keys.inspect}") unless SUPPORTED_ACCOUNTS.keys.collect(&:downcase).include? @header.downcase
  reset
end