Class: IOStreams::Tabular::Parser::Json
- Defined in:
- lib/io_streams/tabular/parser/json.rb
Overview
For parsing a single line of JSON at a time
Instance Method Summary collapse
- #parse(row) ⇒ Object
-
#render(row, header) ⇒ Object
Return the supplied array as a single line JSON string.
- #requires_header? ⇒ Boolean
Instance Method Details
#parse(row) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/io_streams/tabular/parser/json.rb', line 7 def parse(row) return row if row.is_a?(::Hash) unless row.is_a?(String) raise(IOStreams::Errors::TypeMismatch, "Format is :json. Invalid input: #{row.class.name}") end JSON.parse(row) end |
#render(row, header) ⇒ Object
Return the supplied array as a single line JSON string.
18 19 20 21 |
# File 'lib/io_streams/tabular/parser/json.rb', line 18 def render(row, header) hash = header.to_hash(row) hash.to_json end |
#requires_header? ⇒ Boolean
23 24 25 |
# File 'lib/io_streams/tabular/parser/json.rb', line 23 def requires_header? false end |