class NdrImport::FixedWidth::Table

This class maintains the state of a fixed width table mapping and encapsulates the logic required to transform a table of data into “records”. Particular attention has been made to use enumerables throughout to help with the transformation of large quantities of data.

Public Instance Methods

transform_line(line, index) { |klass, fields, index| ... } click to toggle source

This method transforms an incoming line of fixed wwidrh data by applying each of the klass masked mappings to the line and yielding the klass and fields for each mapped klass.

# File lib/ndr_import/fixed_width/table.rb, line 13
def transform_line(line, index)
  return enum_for(:transform_line, line, index) unless block_given?

  masked_mappings.each do |klass, klass_mappings|
    line = fixed_width_columns(line, klass_mappings)
    fields = mapped_line(line, klass_mappings)
    next if fields[:skip].to_s == 'true'.freeze
    yield(klass, fields, index)
  end
end