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, #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


26
27
28
29
# File 'lib/stupidedi/values/repeated_element_val.rb', line 26

def initialize(children, usage)
  @children, @usage =
    children, usage
end

Instance Attribute Details

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

Returns:


18
19
20
# File 'lib/stupidedi/values/repeated_element_val.rb', line 18

def children
  @children
end

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

Returns Schema::SimpleElementUse, Schema::CompositeElementUse

Returns:


22
23
24
# File 'lib/stupidedi/values/repeated_element_val.rb', line 22

def usage
  @usage
end

Class Method Details

.build(children, element_use) ⇒ RepeatedElementVal

Returns:


106
107
108
# File 'lib/stupidedi/values/repeated_element_val.rb', line 106

def build(children, element_use)
  RepeatedElementVal.new(children, element_use)
end

.empty(element_use) ⇒ RepeatedElementVal

Returns:


101
102
103
# File 'lib/stupidedi/values/repeated_element_val.rb', line 101

def empty(element_use)
  RepeatedElementVal.new([], element_use)
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)

89
90
91
92
93
# File 'lib/stupidedi/values/repeated_element_val.rb', line 89

def ==(other)
  eql?(other)
   (other.definition == definition and
    other.children   == @children)
end

#copy(changes = {}) ⇒ RepeatedElementVal

Returns:


32
33
34
35
36
# File 'lib/stupidedi/values/repeated_element_val.rb', line 32

def copy(changes = {})
  RepeatedElementVal.new \
    changes.fetch(:children, @children),
    changes.fetch(:usage, @usage)
end

#element(n, o = nil)


53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stupidedi/values/repeated_element_val.rb', line 53

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)

49
50
51
# File 'lib/stupidedi/values/repeated_element_val.rb', line 49

def empty?
  @children.empty? or @children.all?(&:empty?)
end

#leaf?Boolean

Returns false

Returns:

  • (Boolean)

    false


39
40
41
# File 'lib/stupidedi/values/repeated_element_val.rb', line 39

def leaf?
  false
end

#pretty_print(q)

This method returns an undefined value.


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/stupidedi/values/repeated_element_val.rb', line 67

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


44
45
46
# File 'lib/stupidedi/values/repeated_element_val.rb', line 44

def repeated?
  true
end