Class: GraphViz::Parser::Edge

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Defined in:
lib/graphviz/parser.rb

Instance Method Summary collapse

Instance Method Details

#create_edge(one, two, edge_options, context) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/graphviz/parser.rb', line 142

def create_edge( one, two, edge_options, context )
  # Create edge
  edge = context.graph.add_edge( one, two )
  
  # Add global options
  context.options[:edge].each do |k, v|
    edge[k] = v
  end
  
  # Add custom options
  edge_options.each do |k, v|
    edge[k] = v
  end
  
  # Save edge
  context.edges << edge
end

#create_node(name, context) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/graphviz/parser.rb', line 128

def create_node( name, context )
  # puts "  NEED TO CREATE NODE : #{name}"
  # Create the node
  node = context.graph.add_node( name )
  
  # Add global options
  context.options[:node].each do |k, v|
    node[k] = v
  end
  
  # Save node
  context.nodes[name] = node
end

#eval(context) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/graphviz/parser.rb', line 160

def eval( context )
  one_name = node_one.text_value.gsub( /"/, "" )
  two_name = node_two.text_value.gsub( /"/, "" )
  # puts "EDGE"
  # puts "NODE ONE = #{one_name}"
  # puts "NODE TWO = #{two_name}"
  # puts "OPTIONS = "
  
  # Get or create node one
  one = context.nodes[one_name] || create_node( one_name, context )
    
  # Get or create node two
  two = context.nodes[two_name] || create_node( two_name, context )
  
  # Get options 
  edge_options = {}
  edge_options = options.eval() unless options.terminal?
  
  # Create edge
  create_edge( one, two, edge_options, context )
  
  last_node = two
  other_nodes.elements.each do |e|
    new_node_name = e.next_node.text_value.gsub( /"/, "" )
    # puts "OTHER NODE : #{new_node_name}"
    
    new_node = context.nodes[new_node_name] || create_node( new_node_name, context )
    create_edge( last_node, new_node, edge_options, context )
    
    last_node = new_node
  end
end