Class: RemoteTable::Format::Delimited

Inherits:
RemoteTable::Format show all
Includes:
Textual
Defined in:
lib/remote_table/format/delimited.rb

Constant Summary

Constants included from Textual

Textual::USELESS_CHARACTERS

Instance Attribute Summary

Attributes inherited from RemoteTable::Format

#t

Instance Method Summary collapse

Methods included from Textual

#convert_file_to_utf8!, #crop_rows!, #cut_columns!, #remove_useless_characters!, #skip_rows!

Methods inherited from RemoteTable::Format

#backup_file!, #initialize, #restore_file!

Constructor Details

This class inherits a constructor from RemoteTable::Format

Instance Method Details

#each(&blk) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/remote_table/format/delimited.rb', line 17

def each(&blk)
  backup_file!
  convert_file_to_utf8!
  remove_useless_characters!
  skip_rows!
  ::FasterCSV.foreach(t.local_file.path, fastercsv_options) do |row|
    ordered_hash = ::ActiveSupport::OrderedHash.new
    filled_values = 0
    case row
    when ::FasterCSV::Row
      row.each do |header, value|
        next if header.blank?
        value = '' if value.nil?
        ordered_hash[header] = value
        filled_values += 1 if value.present?
      end
    when ::Array
      index = 0
      row.each do |value|
        value = '' if value.nil?
        ordered_hash[index] = value
        filled_values += 1 if value.present?
        index += 1
      end
    end
    yield ordered_hash if t.properties.keep_blank_rows or filled_values > 0
  end
ensure
  restore_file!
end