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
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

Returns:

  • (Boolean)


23
24
25
# File 'lib/io_streams/tabular/parser/json.rb', line 23

def requires_header?
  false
end