Method: Fech::MapGenerator.generate_row_map_from_file
- Defined in:
- lib/fech/map_generator.rb
.generate_row_map_from_file(source_dir, row_type) ⇒ Object
For a given row type, parses its source file and returns a mapping object for it.
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/fech/map_generator.rb', line 180 def self.generate_row_map_from_file(source_dir, row_type) versions = [] version_indexes = [] data = {} text = open(row_map_file(source_dir, row_type)).read split_char = text.index(/\r/) ? /\r/ : /\n/ rows = text.split(split_char).collect {|x| x.split(',')} rows.each do |row| row = row.collect {|x| x.gsub("\n", "")} if row.first.nil? require 'ruby-debug'; debugger end if row.first.downcase == "canonical" versions = row[1..-1].uniq.collect {|x| x unless (x.nil? || x.empty?)}.compact row.each_with_index {|x, ind| version_indexes << ind unless (x.nil? || x.empty?)}.slice!(1) version_indexes.slice!(0, 1) versions.each {|x| data[x] = [] } elsif row.first.size > 0 canonical = row.first versions.zip(version_indexes).each do |version, row_index| index = row[row_index] data[version][index.to_i - 1] = canonical.to_sym if index.to_i > 0 end end end row_map = {} data.each {|key, value| row_map[key] = value} row_map end |