Class: EDI::Diagram::Branch
- Inherits:
-
Object
- Object
- EDI::Diagram::Branch
- Defined in:
- lib/edi4r/diagrams.rb
Overview
A Branch is a sequence of Nodes. It corresponds to a segment group without its included groups (no sub-branches). A Branch has a name (sg_name
) and comes with descriptory text (desc
).
Note that included TNodes may have side chains/branches (“tails”).
Instance Attribute Summary collapse
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#sg_name ⇒ Object
readonly
Returns the value of attribute sg_name.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Access node list by index, cf.
-
#each ⇒ Object
Iterate through each node of the node list.
-
#expand ⇒ Object
Recursively add “tails” (branches, segment groups) to TNodes.
-
#initialize(key, sg_name, root) ⇒ Branch
constructor
A new Branch object is uniquely identified by the
key
argument that selects the directory entry and itssg_name
(if nto top branch). -
#shift ⇒ Object
Removes and returns the first node from the node list, cf.
-
#size ⇒ Object
Returns size of the node list (number of nodes of this branch).
-
#unshift(node) ⇒ Object
Makes
node
the first node of the node list, cf.
Constructor Details
#initialize(key, sg_name, root) ⇒ Branch
A new Branch object is uniquely identified by the key
argument that selects the directory entry and its sg_name
(if nto top branch). root
is a reference to the Diagram it belongs to.
225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/edi4r/diagrams.rb', line 225 def initialize(key, sg_name, root) # puts "Creating branch for key `#{key+sg_name}'..." @key = key @sg_name = sg_name @root = root @nodelist=[] b = @root.dir.( key+sg_name.to_s ) raise "Lookup failed for key `#{key+sg_name.to_s}'" unless b @desc = b.desc b.each {|obj| @nodelist << Node.create( obj.name, obj.status, obj.maxrep )} end |
Instance Attribute Details
#desc ⇒ Object
Returns the value of attribute desc.
218 219 220 |
# File 'lib/edi4r/diagrams.rb', line 218 def desc @desc end |
#sg_name ⇒ Object (readonly)
Returns the value of attribute sg_name.
219 220 221 |
# File 'lib/edi4r/diagrams.rb', line 219 def sg_name @sg_name end |
Instance Method Details
#[](index) ⇒ Object
Access node list by index, cf. Array
290 291 292 |
# File 'lib/edi4r/diagrams.rb', line 290 def [](index) @nodelist[index] end |
#each ⇒ Object
Iterate through each node of the node list
273 274 275 276 277 278 279 280 |
# File 'lib/edi4r/diagrams.rb', line 273 def each @nodelist.each {|node| yield(node) if node.is_a? TNode and node.tail node.tail.each {|tn| yield(tn)} # Recursion end } end |
#expand ⇒ Object
Recursively add “tails” (branches, segment groups) to TNodes
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/edi4r/diagrams.rb', line 241 def each do |node| if node.is_a? TNode and node.tail == nil # puts "Expanding #{node}" tail = Branch.new(@key, node.name, @root) # Merge TNode with first tail node (trigger segment) trigger_segment = tail.shift node.name = trigger_segment.name if trigger_segment.status != 'M' or trigger_segment.maxrep != 1 raise "#{trigger_segment.name}: Not a trigger seg!" end node.tail = tail. # Recursion! end end self end |
#shift ⇒ Object
Removes and returns the first node from the node list, cf. Array#shift
261 262 263 |
# File 'lib/edi4r/diagrams.rb', line 261 def shift @nodelist.shift end |
#size ⇒ Object
Returns size of the node list (number of nodes of this branch)
296 297 298 |
# File 'lib/edi4r/diagrams.rb', line 296 def size @nodelist.size end |
#unshift(node) ⇒ Object
Makes node
the first node of the node list, cf. Array#unshift
267 268 269 |
# File 'lib/edi4r/diagrams.rb', line 267 def unshift(node) @nodelist.unshift(node) end |