Class: Renderer::Json
- Inherits:
-
Object
- Object
- Renderer::Json
- Defined in:
- lib/renderer/json.rb
Instance Method Summary collapse
- #add_edge(from, to, opts) ⇒ Object
- #add_node(name, opts) ⇒ Object
-
#initialize(file_name, config) ⇒ Json
constructor
A new instance of Json.
- #output ⇒ Object
Constructor Details
#initialize(file_name, config) ⇒ Json
Returns a new instance of Json.
3 4 5 6 7 8 |
# File 'lib/renderer/json.rb', line 3 def initialize(file_name, config) @nodes = [] @edges = [] @file_name = file_name @config = config end |
Instance Method Details
#add_edge(from, to, opts) ⇒ Object
14 15 16 |
# File 'lib/renderer/json.rb', line 14 def add_edge(from, to, opts) @edges << {id: "#{from}-#{to}", source: from, target: to, label: opts[:label]} end |
#add_node(name, opts) ⇒ Object
10 11 12 |
# File 'lib/renderer/json.rb', line 10 def add_node(name, opts) @nodes << {id: name, label: name} end |
#output ⇒ Object
18 19 20 21 |
# File 'lib/renderer/json.rb', line 18 def output IO.write(@file_name, {nodes: @nodes, edges: @edges}.to_json) Renderer.copy_asset('view.html', @file_name) end |