Class: ActiveRecordCSVImporter::CSVReader
- Inherits:
-
Object
- Object
- ActiveRecordCSVImporter::CSVReader
- Defined in:
- lib/activerecord_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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/activerecord_csv_importer/csv_reader.rb', line 12 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
28 29 30 |
# File 'lib/activerecord_csv_importer/csv_reader.rb', line 28 def header @header ||= csv_rows.first end |
#rows ⇒ Object
Returns the rows as an Array of Arrays of Strings
33 34 35 |
# File 'lib/activerecord_csv_importer/csv_reader.rb', line 33 def rows @rows ||= csv_rows[1..-1] end |