Class: Tinydot::Digraph
- Inherits:
-
Object
- Object
- Tinydot::Digraph
- Defined in:
- lib/tinydot/digraph.rb
Instance Method Summary collapse
-
#initialize(name, attrs = {}) ⇒ Digraph
constructor
A new instance of Digraph.
- #method_missing(name, *args) ⇒ Object
- #node(attrs = {}) ⇒ Object
- #to_dot ⇒ Object
Constructor Details
#initialize(name, attrs = {}) ⇒ Digraph
Returns a new instance of Digraph.
5 6 7 8 9 10 |
# File 'lib/tinydot/digraph.rb', line 5 def initialize(name, attrs = {}) @name = name @attrs = attrs @nodes = [] @node_attrs = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tinydot/digraph.rb', line 22 def method_missing(name, *args) node = @nodes.select { |node| node.name == name }.first if node.nil? attrs = {} args.each do |arg| case arg when String then attrs[:label] = arg when Hash then attrs.merge!(arg) end end node = Node.new(name, attrs) @nodes << node end node end |
Instance Method Details
#node(attrs = {}) ⇒ Object
12 13 14 |
# File 'lib/tinydot/digraph.rb', line 12 def node(attrs = {}) @node_attrs = attrs end |