lib/quicken/parser.rb in quicken-0.0.2 vs lib/quicken/parser.rb in quicken-0.0.3

- old
+ new

@@ -1,5 +1,8 @@ +require "iconv" +require "kconv" + module Quicken class Parser attr_accessor :file, :date_format, :transactions, :account @@ -12,10 +15,12 @@ def parse! section = nil File.foreach(@file) do |line| + line = convert_to_utf8(line) + if line =~ /^\!(\S+)/ section = extract_section($1) next end @@ -28,11 +33,11 @@ private def build_objects @account = Quicken::Account.new(@account_attrs) unless @account_attrs.empty? - @transactions = @transactions_attrs.collect do |t| + @transactions = @transactions_attrs.collect do |t| t.merge!({:date_format=>@date_format}) unless @date_format.nil? Quicken::Transaction.new(t) end end @@ -58,8 +63,12 @@ def extract_section(section) section.gsub("Type:","").downcase.to_sym end + def convert_to_utf8(string) + return string if Kconv.isutf8(string) + Iconv.conv('UTF-8', 'LATIN1//IGNORE', string) + end end end \ No newline at end of file