lib/bankgiro_inbetalningar/parser.rb in bankgiro_inbetalningar-1.0.0 vs lib/bankgiro_inbetalningar/parser.rb in bankgiro_inbetalningar-1.1.0

- old
+ new

@@ -2,36 +2,27 @@ module BankgiroInbetalningar class Parser attr_accessor :result - def initialize(filename) - @filename = filename + def initialize(data) + @raw_data ||= data.encode('utf-8', 'iso-8859-1') end def run @result = Result.new parse_lines - ensure - @stream.close if @stream end def parse_lines - while @line = next_line + @raw_data.each_line do |line| + @line = line parse_line record_line end end - def next_line - stream.eof? ? nil : stream.readline - end - - def stream - @stream ||= File.open(@filename, 'r:ISO-8859-1:UTF-8') - end - def parse_line if line_parser_class line_parser = line_parser_class.new(@line) line_parser.update(@result) else @@ -218,10 +209,10 @@ def payment deposit.payments.last end def payments - deposits.map { |d| d.payments }.flatten + deposits.map(&:payments).flatten end class Deposit attr_accessor :bgno, :currency, :payments, :date def initialize