Class: EDI::Diagram::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/edi4r/diagrams.rb

Overview

A Node is essentially the representation of a segment in a diagram. It comes in two flavors: Simple nodes (SNode) and T-nodes (TNode) which may have “tails”. “Node” is an abstract class - either create a SNode or a TNode.

Direct Known Subclasses

SNode, TNode

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, status, rep) ⇒ Node

:nodoc:


328
329
330
331
# File 'lib/edi4r/diagrams.rb', line 328

def initialize(name, status, rep) # :nodoc:
  @name, @status, @maxrep = name, status, rep
  #    @template = EDI::Segment.new(name, nil, nil)
end

Instance Attribute Details

#indexObject

Returns the value of attribute index


311
312
313
# File 'lib/edi4r/diagrams.rb', line 311

def index
  @index
end

#maxrepObject (readonly)

Returns the value of attribute maxrep


312
313
314
# File 'lib/edi4r/diagrams.rb', line 312

def maxrep
  @maxrep
end

#nameObject

Returns the value of attribute name


311
312
313
# File 'lib/edi4r/diagrams.rb', line 311

def name
  @name
end

#statusObject (readonly)

Returns the value of attribute status


312
313
314
# File 'lib/edi4r/diagrams.rb', line 312

def status
  @status
end

Class Method Details

.create(name, status, rep) ⇒ Object

name

The node's name, e.g. the segment tag

status

A one-char string like 'M' (mandatory), 'C' (conditional)

rep

The max. number of repetitions of this node as allowed by the diagram specs.


319
320
321
322
323
324
325
326
# File 'lib/edi4r/diagrams.rb', line 319

def Node.create(name, status, rep)
  case name
  when /^SG\d+$/ # T-Node
    return TNode.new(name, status, rep)
  else	   # Simple node
    return SNode.new(name, status, rep)
  end
end

Instance Method Details

#required?Boolean

Returns:

  • (Boolean)

337
338
339
# File 'lib/edi4r/diagrams.rb', line 337

def required?
  (@status =~ /[MR]/) ? true : false
end

#tailObject

Returns nil for an SNode or a reference to the side branch (“tail”) of a TNode.


343
344
345
# File 'lib/edi4r/diagrams.rb', line 343

def tail
  return nil # Only TNode implements this non-trivially
end

#to_sObject


333
334
335
# File 'lib/edi4r/diagrams.rb', line 333

def to_s
  "%3d - %s, %s, %d" % [@index, @name, @status, @maxrep]
end