Class: Stupidedi::Values::RepeatedElementVal

Inherits:
AbstractElementVal show all
Defined in:
lib/stupidedi/values/repeated_element_val.rb

Overview

See Also:

  • B.1.1.3.2 Repeating Data Elements

Instance Attribute Summary collapse

Constructors collapse

Instance Method Summary collapse

Methods inherited from AbstractElementVal

#element?, #size

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

ansi, #ansi

Methods included from Inspect

#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

#childrenArray<AbstractElementVal> (readonly) Also known as: element_vals

Returns:



14
15
16
# File 'lib/stupidedi/values/repeated_element_val.rb', line 14

def children
  @children
end

#usageSchema::SimpleElementUse, Schema::CompositeElementUse (readonly)

Returns Schema::SimpleElementUse, Schema::CompositeElementUse.

Returns:



11
# File 'lib/stupidedi/values/repeated_element_val.rb', line 11

def_delegators :usage, :definition, :descriptor

Class Method Details

.build(children, element_use) ⇒ RepeatedElementVal

Returns:



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

Returns:



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

Returns:

  • (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

Returns:



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

Returns:

  • (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.

Returns:

  • (Boolean)

    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.

Returns:

  • (Boolean)

    true



41
42
43
# File 'lib/stupidedi/values/repeated_element_val.rb', line 41

def repeated?
  true
end