Class: IOStreams::Tabular::Parser::Csv
- Defined in:
- lib/io_streams/tabular/parser/csv.rb
Instance Attribute Summary collapse
-
#csv_parser ⇒ Object
readonly
Returns the value of attribute csv_parser.
Instance Method Summary collapse
-
#initialize ⇒ Csv
constructor
A new instance of Csv.
-
#parse(row) ⇒ Object
Returns [Array] the parsed CSV line.
-
#parse_header(row) ⇒ Object
Returns [Array<String>] the header row.
-
#render(row, header) ⇒ Object
Return the supplied array as a single line CSV string.
Methods inherited from Base
Constructor Details
Instance Attribute Details
#csv_parser ⇒ Object (readonly)
Returns the value of attribute csv_parser.
6 7 8 |
# File 'lib/io_streams/tabular/parser/csv.rb', line 6 def csv_parser @csv_parser end |
Instance Method Details
#parse(row) ⇒ Object
Returns [Array] the parsed CSV line
23 24 25 26 27 28 29 |
# File 'lib/io_streams/tabular/parser/csv.rb', line 23 def parse(row) return row if row.is_a?(::Array) raise(IOStreams::Errors::TypeMismatch, "Format is :csv. Invalid input: #{row.class.name}") unless row.is_a?(String) parse_line(row) end |
#parse_header(row) ⇒ Object
Returns [Array<String>] the header row. Returns nil if the row is blank.
14 15 16 17 18 19 20 |
# File 'lib/io_streams/tabular/parser/csv.rb', line 14 def parse_header(row) return row if row.is_a?(::Array) raise(IOStreams::Errors::InvalidHeader, "Format is :csv. Invalid input header: #{row.class.name}") unless row.is_a?(String) parse_line(row) end |
#render(row, header) ⇒ Object
Return the supplied array as a single line CSV string.
32 33 34 35 |
# File 'lib/io_streams/tabular/parser/csv.rb', line 32 def render(row, header) array = header.to_array(row) render_array(array) end |