Skip to content
This repository
Browse code

bugfix: make MapGenerator Ruby 1.9 compatible

  • Loading branch information...
commit fb544f368a20eb4e7f0f39337ce4717d03714a7e 1 parent c02ad60
Michael Strickland authored April 11, 2012
1  fech.gemspec
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
24 24
   if RUBY_VERSION < "1.9"
25 25
     s.add_development_dependency "linecache", "0.43"
26 26
     s.add_development_dependency "ruby-debug"
  27
+    s.add_development_dependency "iconv"
27 28
   end
28 29
   if RUBY_VERSION >= "1.9"
29 30
     s.add_development_dependency "ruby-debug19"
11  lib/fech/map_generator.rb
... ...
@@ -1,3 +1,5 @@
  1
+require 'iconv'
  2
+
1 3
 module Fech
2 4
   
3 5
   # Helper class to generate mapping hashes from source csv data.
@@ -71,7 +73,14 @@ def self.convert_header_file_to_row_files(source_dir)
71 73
       # exists for it. If maps for two different versions are identical, they
72 74
       # are combined.
73 75
       FILING_VERSIONS.each do |version|
74  
-        Fech::Csv.foreach(version_summary_file(source_dir, version)) do |row|
  76
+        filepath = version_summary_file(source_dir, version)
  77
+
  78
+        # Clean the source files by removing unparseable characters
  79
+        ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
  80
+        valid_string = ic.iconv(open(filepath).read << ' ')[0..-2]
  81
+        open(filepath, 'w').write(valid_string)
  82
+
  83
+        Fech::Csv.foreach(filepath) do |row|
75 84
           # Each row of a version summary file contains the ordered list of
76 85
           # column names.
77 86
           data[row.first] ||= {}

0 notes on commit fb544f3

Please sign in to comment.
Something went wrong with that request. Please try again.