Class: Vedeu::Renderers::JSON

Inherits:
File
  • Object
show all
Defined in:
lib/vedeu/output/renderers/json.rb

Overview

Renders a Terminal::Buffer as JSON.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Vedeu::Renderers::JSON

Returns a new instance of Vedeu::Renderers::JSON.

Parameters:

  • options (Hash) (defaults to: {})


13
14
15
# File 'lib/vedeu/output/renderers/json.rb', line 13

def initialize(options = {})
  @options = options || {}
end

Instance Attribute Details

#optionsHash<Symbol => void> (private) Originally defined in module Options

Combines the options provided at instantiation with the default values.

Returns:

  • (Hash<Symbol => void>)

Instance Method Details

#as_hash(output) ⇒ Array (private)

Parameters:

Returns:

  • (Array)


48
49
50
51
52
# File 'lib/vedeu/output/renderers/json.rb', line 48

def as_hash(output)
  return output if output.is_a?(Hash)

  output.content.map(&:to_hash)
end

#clearString

Render a cleared output.

Returns:

  • (String)


20
21
22
23
24
25
26
# File 'lib/vedeu/output/renderers/json.rb', line 20

def clear
  json = parse({})

  super(json)

  json
end

#parse(output) ⇒ String (private)

Parameters:

Returns:

  • (String)


42
43
44
# File 'lib/vedeu/output/renderers/json.rb', line 42

def parse(output)
  ::JSON.pretty_generate(as_hash(output))
end

#render(output) ⇒ String

Parameters:

Returns:

  • (String)


30
31
32
33
34
35
36
# File 'lib/vedeu/output/renderers/json.rb', line 30

def render(output)
  json = parse(output)

  super(json)

  json
end