Class: LoaderRuby::Loaders::Csv

Inherits:
Base
  • Object
show all
Defined in:
lib/loader_ruby/loaders/csv.rb

Constant Summary collapse

EXTENSIONS =
%w[.csv .tsv].freeze

Instance Method Summary collapse

Instance Method Details

#load(path, row_as_document: false, **opts) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/loader_ruby/loaders/csv.rb', line 10

def load(path, row_as_document: false, **opts)
  check_file_exists!(path)
  check_file_size!(path)

  separator = path.end_with?(".tsv") ? "\t" : ","
  table = ::CSV.read(path, headers: true, col_sep: separator)

  if row_as_document
    load_rows_as_documents(path, table)
  else
    load_as_single_document(path, table)
  end
end