Class: EDI::Diagram::Node
- Inherits:
-
Object
- Object
- EDI::Diagram::Node
- 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.
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#maxrep ⇒ Object
readonly
Returns the value of attribute maxrep.
-
#name ⇒ Object
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.create(name, status, rep) ⇒ Object
name
-
The node’s name, e.g.
Instance Method Summary collapse
-
#initialize(name, status, rep) ⇒ Node
constructor
:nodoc:.
- #required? ⇒ Boolean
-
#tail ⇒ Object
Returns
nil
for an SNode or a reference to the side branch (“tail”) of a TNode. - #to_s ⇒ Object
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
#index ⇒ Object
Returns the value of attribute index.
311 312 313 |
# File 'lib/edi4r/diagrams.rb', line 311 def index @index end |
#maxrep ⇒ Object (readonly)
Returns the value of attribute maxrep.
312 313 314 |
# File 'lib/edi4r/diagrams.rb', line 312 def maxrep @maxrep end |
#name ⇒ Object
Returns the value of attribute name.
311 312 313 |
# File 'lib/edi4r/diagrams.rb', line 311 def name @name end |
#status ⇒ Object (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
337 338 339 |
# File 'lib/edi4r/diagrams.rb', line 337 def required? (@status =~ /[MR]/) ? true : false end |
#tail ⇒ Object
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_s ⇒ Object
333 334 335 |
# File 'lib/edi4r/diagrams.rb', line 333 def to_s "%3d - %s, %s, %d" % [@index, @name, @status, @maxrep] end |