Class: Stupidedi::Values::SegmentVal
- Inherits:
-
AbstractVal
- Object
- AbstractVal
- Stupidedi::Values::SegmentVal
- Defined in:
- lib/stupidedi/values/segment_val.rb
Overview
Instance Attribute Summary collapse
- #children ⇒ Array<AbstractElementVal> readonly
- #position ⇒ Position readonly
- #usage ⇒ SegmentUse readonly
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #copy(changes = {}) ⇒ SegmentVal
- #element(m, n = nil, o = nil) ⇒ AbstractElementVal
-
#initialize(children, usage, position) ⇒ SegmentVal
constructor
A new instance of SegmentVal.
-
#inspect ⇒ String
:nocov:.
-
#leaf? ⇒ Boolean
False.
-
#pretty_print(q)
:nocov:.
-
#segment?
Is this a SegmentVal or InvalidSegmentVal?.
-
#size ⇒ Integer
Number of segments in this subtree.
- #valid? ⇒ Boolean
Methods inherited from AbstractVal
#blank?, #characters, #component?, #composite?, #definition, #descriptor, #element?, #empty?, #functional_group?, #interchange?, #invalid?, #loop?, #present?, #repeated?, #separator?, #simple?, #table?, #transaction_set?, #transmission?
Methods included from Color
Constructor Details
#initialize(children, usage, position) ⇒ SegmentVal
Returns a new instance of SegmentVal.
22 23 24 25 |
# File 'lib/stupidedi/values/segment_val.rb', line 22 def initialize(children, usage, position) @children, @usage, @position = children, usage, position end |
Instance Attribute Details
#children ⇒ Array<AbstractElementVal> (readonly)
14 15 16 |
# File 'lib/stupidedi/values/segment_val.rb', line 14 def children @children end |
#position ⇒ Position (readonly)
20 21 22 |
# File 'lib/stupidedi/values/segment_val.rb', line 20 def position @position end |
#usage ⇒ SegmentUse (readonly)
11 |
# File 'lib/stupidedi/values/segment_val.rb', line 11 def_delegators :usage, :definition, :descriptor, :id |
Instance Method Details
#==(other) ⇒ Boolean
98 99 100 101 102 |
# File 'lib/stupidedi/values/segment_val.rb', line 98 def ==(other) eql?(other) or (other.definition == definition and other.children == @children) end |
#copy(changes = {}) ⇒ SegmentVal
28 29 30 31 32 33 |
# File 'lib/stupidedi/values/segment_val.rb', line 28 def copy(changes = {}) SegmentVal.new \ changes.fetch(:children, @children), changes.fetch(:usage, @usage), changes.fetch(:position, @position) end |
#element(m, n = nil, o = nil) ⇒ AbstractElementVal
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/stupidedi/values/segment_val.rb', line 56 def element(m, n = nil, o = nil) unless m > 0 raise ArgumentError, "m must be positive" end unless n.nil? @children.at(m - 1).element(n, o) else @children.at(m - 1) end end |
#inspect ⇒ String
:nocov:
92 93 94 |
# File 'lib/stupidedi/values/segment_val.rb', line 92 def inspect ansi.segment(ansi.bold(definition.id.to_s)) end |
#leaf? ⇒ Boolean
Returns false.
41 42 43 |
# File 'lib/stupidedi/values/segment_val.rb', line 41 def leaf? false end |
#pretty_print(q)
This method returns an undefined value.
:nocov:
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/stupidedi/values/segment_val.rb', line 71 def pretty_print(q) id = definition.try do |d| ansi.bold("[#{d.id}: #{d.name}]") end q.text(ansi.segment("SegmentVal#{id}")) q.group(2, "(", ")") do q.breakable "" @children.each do |e| unless q.current_group.first? q.text "," q.breakable end q.pp e end end end |
#segment?
Is this a Stupidedi::Values::SegmentVal or InvalidSegmentVal?
51 52 53 |
# File 'lib/stupidedi/values/segment_val.rb', line 51 def segment? true end |
#size ⇒ Integer
Number of segments in this subtree
36 37 38 |
# File 'lib/stupidedi/values/segment_val.rb', line 36 def size 1 end |
#valid? ⇒ Boolean
45 46 47 |
# File 'lib/stupidedi/values/segment_val.rb', line 45 def valid? true end |