Class: CSVImporter::CSVReader

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

Overview

Reads, sanitize and parse a CSV file

Instance Method Summary collapse

Instance Method Details

#csv_rowsObject



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

def csv_rows
  @csv_rows ||= begin
    sane_content = sanitize_content(read_content)
    separator = detect_separator(sane_content)
    cells = CSV.parse(sane_content, col_sep: separator, quote_char: quote_char, skip_blanks: true, encoding: encoding)
    sanitize_cells(cells)
  end
end

#headerObject

Returns the header as an Array of Strings



23
24
25
# File 'lib/csv_importer/csv_reader.rb', line 23

def header
  @header ||= csv_rows.first
end

#rowsObject

Returns the rows as an Array of Arrays of Strings



28
29
30
# File 'lib/csv_importer/csv_reader.rb', line 28

def rows
  @rows ||= csv_rows[1..-1]
end