Class: Vedeu::Renderers::JSON

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

Overview

Renders a VirtualBuffer or Output as JSON.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ Vedeu::Renderers::JSON

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

Parameters:



25
26
27
# File 'lib/vedeu/output/renderers/json.rb', line 25

def initialize(output)
  @output = output
end

Instance Attribute Details

#outputArray<Array<Vedeu::Char>> (readonly, protected)

Returns:



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

def output
  @output
end

Class Method Details

.render(output) ⇒ String

Parameters:

Returns:

  • (String)


10
11
12
# File 'lib/vedeu/output/renderers/json.rb', line 10

def self.render(output)
  new(output).render
end

Instance Method Details

#renderString

Returns:

  • (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vedeu/output/renderers/json.rb', line 30

def render
  return '' if output.nil? || output.empty?

  out = ''
  Array(output).each do |line|
    out << ''
    line.each do |char|
      out << char.to_json
      out << "\n"
    end
    out << "\n"
  end
  out
end