class Impex::FileFormatter

Public Class Methods

build(csv_file) click to toggle source
# File lib/impex/file_formatter.rb, line 9
def build(csv_file)
  table = find_table_name(csv_file.path)
  file_config = {
    table: table
  }

  file = Impex::File.new(csv_file, file_config)

  ::CSV.read(csv_file, headers: true).each do |row|
    file << Impex::Row.new(row.to_h, file_config)
  end
  file
end
find_table_name(filename) click to toggle source
# File lib/impex/file_formatter.rb, line 23
def find_table_name(filename)
  filename[/\/(\w+)\/\w+.csv$/, 1]
end