Class: Stupidedi::Values::RepeatedElementVal
- Inherits:
-
AbstractElementVal
- Object
- AbstractVal
- AbstractElementVal
- Stupidedi::Values::RepeatedElementVal
- Defined in:
- lib/stupidedi/values/repeated_element_val.rb
Overview
Instance Attribute Summary collapse
- #children ⇒ Array<AbstractElementVal> (also: #element_vals) readonly
-
#usage ⇒ Schema::SimpleElementUse, Schema::CompositeElementUse
readonly
Schema::SimpleElementUse, Schema::CompositeElementUse.
Constructors collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #copy(changes = {}) ⇒ RepeatedElementVal
- #element(n, o = nil)
- #empty? ⇒ Boolean
-
#initialize(children, usage) ⇒ RepeatedElementVal
constructor
A new instance of RepeatedElementVal.
-
#leaf? ⇒ Boolean
False.
-
#pretty_print(q)
:nocov:.
-
#repeated? ⇒ Boolean
True.
Methods inherited from AbstractElementVal
Methods inherited from AbstractVal
#blank?, #characters, #component?, #composite?, #definition, #descriptor, #element?, #functional_group?, #interchange?, #invalid?, #loop?, #present?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?, #valid?
Methods included from Color
Methods included from Inspect
Constructor Details
#initialize(children, usage) ⇒ RepeatedElementVal
Returns a new instance of RepeatedElementVal.
23 24 25 26 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 23 def initialize(children, usage) @children, @usage = children, usage end |
Instance Attribute Details
#children ⇒ Array<AbstractElementVal> (readonly) Also known as: element_vals
14 15 16 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 14 def children @children end |
#usage ⇒ Schema::SimpleElementUse, Schema::CompositeElementUse (readonly)
Returns Schema::SimpleElementUse, Schema::CompositeElementUse.
11 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 11 def_delegators :usage, :definition, :descriptor |
Class Method Details
.build(children, element_use) ⇒ RepeatedElementVal
105 106 107 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 105 def build(children, element_use) RepeatedElementVal.new(children, element_use) end |
.empty(element_use) ⇒ RepeatedElementVal
100 101 102 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 100 def empty(element_use) RepeatedElementVal.new([], element_use) end |
Instance Method Details
#==(other) ⇒ Boolean
88 89 90 91 92 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 88 def ==(other) eql?(other) or \ (other.definition == definition and other.children == @children) end |
#copy(changes = {}) ⇒ RepeatedElementVal
29 30 31 32 33 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 29 def copy(changes = {}) RepeatedElementVal.new \ changes.fetch(:children, @children), changes.fetch(:usage, @usage) end |
#element(n, o = nil)
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 50 def element(n, o = nil) unless n > 0 raise ArgumentError, "n must be positive" end unless o.nil? @children.at(n - 1).element(o) else @children.at(n - 1) end end |
#empty? ⇒ Boolean
46 47 48 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 46 def empty? @children.empty? or @children.all?(&:empty?) end |
#leaf? ⇒ Boolean
Returns false.
36 37 38 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 36 def leaf? false end |
#pretty_print(q)
This method returns an undefined value.
:nocov:
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 65 def pretty_print(q) if @children.empty? id = definition.try do |d| ansi.bold("[#{d.id.to_s}: #{d.name.to_s}]") end q.text(ansi.repeated("RepeatedElementVal#{id}")) else q.text(ansi.repeated("RepeatedElementVal")) 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 end |
#repeated? ⇒ Boolean
Returns true.
41 42 43 |
# File 'lib/stupidedi/values/repeated_element_val.rb', line 41 def repeated? true end |