Class: CSVImporter::CSVReader
- Inherits:
-
Object
- Object
- CSVImporter::CSVReader
- Defined in:
- lib/csv_importer/csv_reader.rb
Overview
Reads, sanitize and parse a CSV file
Instance Method Summary collapse
- #csv_rows ⇒ Object
-
#header ⇒ Object
Returns the header as an Array of Strings.
-
#rows ⇒ Object
Returns the rows as an Array of Arrays of Strings.
Instance Method Details
#csv_rows ⇒ Object
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 |
#header ⇒ Object
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 |
#rows ⇒ Object
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 |