Skip to content

Commit

Permalink
ensured that psych parser is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Lea Voget committed Apr 20, 2012
1 parent 3231b04 commit 216eb0e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/mt940.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# encoding: utf-8
require 'mt940/customer_statement_message'

class MT940
Expand Down Expand Up @@ -221,7 +220,7 @@ def parse_content(content)
else
@not_implemented_fields ||= []
@not_implemented_fields << [code, content]
$stderr << "code not implemented: code:#{code} content:»#{content}«\n" if $DEBUG
$stderr << "code not implemented: code:#{code} content:\"#{content}\"\n" if $DEBUG
end
end
end
Expand All @@ -231,22 +230,23 @@ def parse_content(content)
end
end


class << self
def parse(text)
new_text = text.clone.force_encoding("ISO-8859-1")
if !new_text.valid_encoding?
warn "Your data is not in binary format"
new_text = text.clone.encode("ISO-8859-1")
if !new_text.valid_encoding?
puts "WOOOOT WHAT IS THE RIGHT ENCODING?"
raise "Your data could not be encoded in binary format"
end
end
text = new_text # WOOOT refactor?
text << "\r\n" if text[-1,1] == '-'
raw_sheets = text.split(/^-\r\n/).map { |sheet| sheet.gsub(/\r\n(?!:)/, '') }
new_text << "\r\n" if new_text[-1,1] == '-'
raw_sheets = new_text.split(/^-\r\n/).map { |sheet| sheet.gsub(/\r\n(?!:)/, '') }
sheets = raw_sheets.map { |raw_sheet| parse_sheet(raw_sheet) }
end



private
def parse_sheet(sheet)
lines = sheet.split("\r\n")
Expand Down
4 changes: 3 additions & 1 deletion test/test_customer_statement_message.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'helper'
require_relative 'helper'
require 'yaml'
YAML::ENGINE.yamler = 'psych'


# $DEBUG = true
class TestCustomerStatementMessage < Test::Unit::TestCase
Expand Down
4 changes: 3 additions & 1 deletion test/test_mt940.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'helper'
require_relative 'helper'
require 'yaml'
YAML::ENGINE.yamler = 'psych'


# $DEBUG = true
class TestMt940 < Test::Unit::TestCase
Expand Down

0 comments on commit 216eb0e

Please sign in to comment.