Class: CsvToSqlite::CsvReader
- Inherits:
-
Object
- Object
- CsvToSqlite::CsvReader
- Defined in:
- lib/csv_reader.rb
Instance Method Summary collapse
-
#initialize(file_path) ⇒ CsvReader
constructor
A new instance of CsvReader.
- #load_file ⇒ Object
- #separator ⇒ Object
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_file ⇒ Object
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 |
#separator ⇒ Object
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 |