Class: CsvToSqlite::CsvReader

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

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ CsvReader

Returns a new instance of CsvReader.



7
8
9
# File 'lib/csv_reader.rb', line 7

def initialize file_path
  @file_path = file_path
end

Instance Method Details

#load_fileObject



11
12
13
# File 'lib/csv_reader.rb', line 11

def load_file
  CSV.parse(File.read(@file_path), headers: true, col_sep: separator)
end

#separatorObject



15
16
17
18
19
20
21
# File 'lib/csv_reader.rb', line 15

def separator
  first_line = File.open(@file_path) do |file|
    line = file.readline
    return ";" if line.include? ";"
    return "," if line.include? ","
  end
end