module Eaternet::Lives_1_0::CsvParser

Public Instance Methods

adapter_name() click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 4
def adapter_name
  fail 'Override #adapter_name with a name for log output, e.g. "SF"'
end
convert(csv:, to_type:) click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 12
def convert(csv:, to_type:)
  csv_map(csv) { |row| try_to_create to_type, from_csv_row: row }.compact
end
csv_map(filename) { |row| ... } click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 22
def csv_map(filename)
  csv_rows(filename).lazy.map { |row| yield(row) }
end
csv_rows(filename) click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 26
def csv_rows(filename)
  csv_reader(path: File.join(zip_dir, filename))
end
map_csv() { |row| ... } click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 16
def map_csv
  CSV.new(File.open(table_file, encoding: 'utf-8'), headers: true)
     .lazy
     .map { |row| yield(row) }
end
try_to_create(entity_type, from_csv_row:) click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 34
def try_to_create(entity_type, from_csv_row:)
  send(entity_type, from_csv_row)
rescue ArgumentError => e
  logger.warn("#{adapter_name} LIVES adapter") do
    "Couldn't create a LIVES #{entity_type} from #{from_csv_row.inspect}: #{e}"
  end
  nil
end
zip_dir() click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 30
def zip_dir
  Util.download_and_extract_zipfile(zip_file_url)
end
zip_file_url() click to toggle source
# File lib/eaternet/lives_1_0/csv_parser.rb, line 8
def zip_file_url
  fail 'Override #zip_file_url with the zip archive location'
end