Class: AST2Dot
- Inherits:
-
Object
- Object
- AST2Dot
- Defined in:
- lib/ast2dot.rb,
lib/ast2dot/version.rb,
lib/ast2dot/node_label.rb
Defined Under Namespace
Classes: NodeLabel
Constant Summary collapse
- VERSION =
'0.1.1'
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
Returns the value of attribute ast.
-
#graph_edges ⇒ Object
readonly
Returns the value of attribute graph_edges.
-
#node_labels ⇒ Object
readonly
Returns the value of attribute node_labels.
Class Method Summary collapse
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(code) ⇒ AST2Dot
constructor
A new instance of AST2Dot.
- #render ⇒ Object
Constructor Details
#initialize(code) ⇒ AST2Dot
Returns a new instance of AST2Dot.
12 13 14 15 |
# File 'lib/ast2dot.rb', line 12 def initialize(code) @ast = RubyVM::AbstractSyntaxTree.parse(code) @template = File.read(File.('templates/default.dot.erb', __dir__)) end |
Instance Attribute Details
#ast ⇒ Object (readonly)
Returns the value of attribute ast.
10 11 12 |
# File 'lib/ast2dot.rb', line 10 def ast @ast end |
#graph_edges ⇒ Object (readonly)
Returns the value of attribute graph_edges.
10 11 12 |
# File 'lib/ast2dot.rb', line 10 def graph_edges @graph_edges end |
#node_labels ⇒ Object (readonly)
Returns the value of attribute node_labels.
10 11 12 |
# File 'lib/ast2dot.rb', line 10 def node_labels @node_labels end |
Class Method Details
.render(code) ⇒ Object
6 7 8 |
# File 'lib/ast2dot.rb', line 6 def self.render(code) new(code).render end |
Instance Method Details
#export ⇒ Object
17 18 |
# File 'lib/ast2dot.rb', line 17 def export end |
#render ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/ast2dot.rb', line 20 def render @graph_edges = [] @node_labels = Hash.new node_labelling(ast) graph_data = ERB.new(@template, nil, '-').result(binding) graph_data.lines.map(&:rstrip).join("\n") end |