Class: Stupidedi::Values::LoopVal

Inherits:
AbstractVal show all
Extended by:
Forwardable
Includes:
SegmentValGroup
Defined in:
lib/stupidedi/values/loop_val.rb

Overview

See Also:

  • B.1.1.3.12.2 Data Segment Groups
  • B.1.1.3.12.4 Loops of Data Segments

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SegmentValGroup

#leaf?

Methods inherited from AbstractVal

#blank?, #characters, #component?, #composite?, #element?, #empty?, #functional_group?, #interchange?, #invalid?, #present?, #repeated?, #segment?, #separator?, #simple?, #size, #table?, #transaction_set?, #transmission?, #valid?

Methods included from Color

ansi, #ansi

Constructor Details

#initialize(definition, children) ⇒ LoopVal

Returns a new instance of LoopVal.



20
21
22
23
# File 'lib/stupidedi/values/loop_val.rb', line 20

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

Instance Attribute Details

#childrenArray<SegmentVal, LoopVal> (readonly)

Returns:



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

def children
  @children
end

#definitionLoopDef (readonly)

Returns:

  • (LoopDef)


12
13
14
# File 'lib/stupidedi/values/loop_val.rb', line 12

def definition
  @definition
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/stupidedi/values/loop_val.rb', line 63

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

#copy(changes = {}) ⇒ LoopVal

Returns:



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

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

#inspectString

Returns:



58
59
60
# File 'lib/stupidedi/values/loop_val.rb', line 58

def inspect
  ansi.loop("Loop") << "(#{@children.map(&:inspect).join(', ')})"
end

#loop?Object

Returns:

  • true



34
35
36
# File 'lib/stupidedi/values/loop_val.rb', line 34

def loop?
  true
end

#pretty_print(q) ⇒ void

This method returns an undefined value.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/stupidedi/values/loop_val.rb', line 39

def pretty_print(q)
  id = @definition.try do |d|
    ansi.bold("[#{d.id.to_s}]")
  end

  q.text(ansi.loop("LoopVal#{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