Module: RemoteTable::FixedWidth

Defined in:
lib/remote_table/fixed_width.rb

Overview

Parses plaintext fixed-width files using github.com/seamusabshere/fixed_width

Constant Summary collapse

TRAP_EVERYTHING =
proc { |_| true }

Instance Method Summary collapse

Instance Method Details

#_eachObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/remote_table/fixed_width.rb', line 25

def _each
  require 'fixed_width-multibyte'

  fixed_width_parser.parse[:rows].each do |row|
    some_value_present = false
    hash = ::ActiveSupport::OrderedHash.new
    row.each do |k, v|
      v = v.to_s.strip
      if not some_value_present and not keep_blank_rows and v.present?
        some_value_present = true
      end
      hash[k] = v
    end
    if some_value_present or keep_blank_rows
      yield hash
    end
  end
ensure
  local_copy.cleanup
end

#preprocess!Object



16
17
18
19
20
21
22
23
# File 'lib/remote_table/fixed_width.rb', line 16

def preprocess!
  delete_harmful!
  convert_eol_to_unix!
  transliterate_whole_file_to_utf8!
  crop_rows!
  skip_rows!
  cut_columns!
end