Class: GraphBuilder::Chain

Inherits:
Node show all
Defined in:
lib/graph_builder.rb

Instance Attribute Summary

Attributes inherited from Base

#children, #opts, #parent

Instance Method Summary collapse

Methods inherited from Node

#add_leaf, #add_node, #to_s

Methods inherited from Base

#ancestors, #debug, #depth, #dump, #empty?, #indent, #initialize

Constructor Details

This class inherits a constructor from GraphBuilder::Base

Instance Method Details

#first_thingsObject



67
# File 'lib/graph_builder.rb', line 67

def first_things;  children.map(&:first_things).first; end

#last_thingsObject



66
# File 'lib/graph_builder.rb', line 66

def last_things;   children.map(&:last_things).last;   end

#processObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/graph_builder.rb', line 69

def process
  children.each &:process

  debug{"processing #{self}"}
  debug{"       children: #{children.map(&:to_s).join(',')}" }
  
  # Connect the pairs of a chain:
  # connect all last_things of child with the first_things of the following child
  children.each_cons(2) do |pair|
    debug{"       pair: (#{pair.first},#{pair.last})"}
    froms = [pair.first.last_things].flatten
    tos   = [pair.last.first_things].flatten
    debug{"       froms= last_things of #{pair.first}: #{froms.map(&:to_s).join(',')}"}
    debug{"       tos=  first_things of #{pair.last}:  #{tos.map(&:to_s).join(',')}"}
    tos.each do |to|
      froms.each do |from|
        debug{"       link from=#{from} to=#{to}"}
        from.link_to to 
      end
    end
  end
end