Class: Stupidedi::Values::RepeatedElementVal

Inherits:
AbstractElementVal show all
Extended by:
Forwardable
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.



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



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

def children
  @children
end

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

Returns Schema::SimpleElementUse, Schema::CompositeElementUse.

Returns:



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

def usage
  @usage
end

Class Method Details

.build(children, element_use) ⇒ RepeatedElementVal

Returns:



103
104
105
# File 'lib/stupidedi/values/repeated_element_val.rb', line 103

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

.empty(element_use) ⇒ RepeatedElementVal

Returns:



98
99
100
# File 'lib/stupidedi/values/repeated_element_val.rb', line 98

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

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
# File 'lib/stupidedi/values/repeated_element_val.rb', line 86

def ==(other)
  eql?(other)
   (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) ⇒ Object



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) ⇒ void

This method returns an undefined value.



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

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