Class: Impex::FileFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/impex/file_formatter.rb

Class Method Summary collapse

Class Method Details

.build(csv_file) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# 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) ⇒ Object



23
24
25
# File 'lib/impex/file_formatter.rb', line 23

def find_table_name(filename)
  filename[/\/(\w+)\/\w+.csv$/, 1]
end