Class: IOStreams::Tabular::Parser::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/io_streams/tabular/parser/json.rb

Overview

For parsing a single line of JSON at a time

Instance Method Summary collapse

Instance Method Details

#parse(row) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/io_streams/tabular/parser/json.rb', line 7

def parse(row)
  return row if row.is_a?(::Hash)

  raise(IOStreams::Errors::TypeMismatch, "Format is :json. Invalid input: #{row.class.name}") unless row.is_a?(String)

  JSON.parse(row)
end

#render(row, header) ⇒ Object

Return the supplied array as a single line JSON string.



16
17
18
19
# File 'lib/io_streams/tabular/parser/json.rb', line 16

def render(row, header)
  hash = header.to_hash(row)
  hash.to_json
end

#requires_header?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/io_streams/tabular/parser/json.rb', line 21

def requires_header?
  false
end