class VisualizeRuby::Graph

Attributes

edges[RW]
name[RW]
nodes[RW]

Public Class Methods

new(ruby_code: nil, name: nil, ast: nil, **opts) click to toggle source
# File lib/visualize_ruby/graph.rb, line 5
def initialize(ruby_code: nil, name: nil, ast: nil, **opts)
  @name              = name.to_s if name
  @nodes, @edges     = (ast ? Parser.new(ast: ast) : Parser.new(ruby_code)).parse
  @ast               = ast
  @graph_viz_options = opts
end

Public Instance Methods

options(**args) click to toggle source
# File lib/visualize_ruby/graph.rb, line 12
def options(**args)
  @graph_viz_options.merge!(args)
  @graph_viz_options
end
to_hash() click to toggle source
# File lib/visualize_ruby/graph.rb, line 17
def to_hash
  {
      name:  name,
      edges: edges.map(&:to_a),
      nodes: nodes.map(&:to_a),
  }
end
uniq_elements!() click to toggle source
# File lib/visualize_ruby/graph.rb, line 25
def uniq_elements!
  @edges = edges.uniq
  @nodes = nodes.uniq
  self
end