Class: Stupidedi::Schema::LoopDef

Inherits:
AbstractDef show all
Extended by:
Forwardable
Includes:
Inspect
Defined in:
lib/stupidedi/schema/loop_def.rb

Overview

See Also:

Instance Attribute Summary (collapse)

Constructors (collapse)

Instance Method Summary (collapse)

Methods included from Inspect

#inspect

Methods inherited from AbstractDef

#component?, #composite?, #definition?, #element?, #functional_group?, #interchange?, #repeated?, #segment?, #simple?, #table?, #transaction_set?, #usage?

Constructor Details

- (LoopDef) initialize(id, repeat_count, header_segment_uses, loop_defs, trailer_segment_uses, parent)



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/stupidedi/schema/loop_def.rb', line 34

def initialize(id, repeat_count, header_segment_uses, loop_defs, trailer_segment_uses, parent)
  @id, @repeat_count, @header_segment_uses, @loop_defs, @trailer_segment_uses, @parent =
    id, repeat_count, header_segment_uses, loop_defs, trailer_segment_uses, parent

  # Delay re-parenting until the entire definition tree has a root
  # to prevent unnecessarily copying objects
  unless parent.nil?
    @header_segment_uses  = @header_segment_uses.map{|x| x.copy(:parent => self) }
    @loop_defs            = @loop_defs.map{|x| x.copy(:parent => self) }
    @trailer_segment_uses = @trailer_segment_uses.map{|x| x.copy(:parent => self) }
  end
end

Instance Attribute Details

- (Array<SegmentUse>) header_segment_uses (readonly)



18
19
20
# File 'lib/stupidedi/schema/loop_def.rb', line 18

def header_segment_uses
  @header_segment_uses
end

- (String) id (readonly)



12
13
14
# File 'lib/stupidedi/schema/loop_def.rb', line 12

def id
  @id
end

- (Array<LoopDef>) loop_defs (readonly)



24
25
26
# File 'lib/stupidedi/schema/loop_def.rb', line 24

def loop_defs
  @loop_defs
end

- (LoopDef, TableDef) parent (readonly)



27
28
29
# File 'lib/stupidedi/schema/loop_def.rb', line 27

def parent
  @parent
end

- (RepeatCount) repeat_count (readonly)



15
16
17
# File 'lib/stupidedi/schema/loop_def.rb', line 15

def repeat_count
  @repeat_count
end

- (Array<SegmentUse>) trailer_segment_uses (readonly)



21
22
23
# File 'lib/stupidedi/schema/loop_def.rb', line 21

def trailer_segment_uses
  @trailer_segment_uses
end

Class Method Details

+ (LoopDef) build(id, repeat_count, *children)



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/stupidedi/schema/loop_def.rb', line 133

def build(id, repeat_count, *children)
  header, children   = children.split_when{|x| x.is_a?(LoopDef) }
  loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) }

  # @todo: Ensure there is at least one SegmentUse in header
  if header.empty?
    raise Exceptions::InvalidSchemaError,
      "first child must be a SegmentUse"
  elsif header.head.repeat_count.include?(2)
    "first child must have RepeatCount.bounded(1)"
  end

  new(id, repeat_count, header, loop_defs, trailer, nil)
end

Instance Method Details

- (Boolean) bounded?

See Also:

  • B.1.1.3.11.1 Loop Control Segments
  • B.1.1.3.12.4 Loops of Data Segments Bounded Loops


64
65
66
67
# File 'lib/stupidedi/schema/loop_def.rb', line 64

def bounded?
  @header_segment_uses.head.definition.id == :LS and
  @trailer_segment_uses.last.definition.id == :LE
end

- (Array<SegmentUse, LoopDef>) children



80
81
82
# File 'lib/stupidedi/schema/loop_def.rb', line 80

def children
  @header_segment_uses + @loop_defs + @trailer_segment_uses
end

- (AbstractSet<CodeList>) code_lists



94
95
96
# File 'lib/stupidedi/schema/loop_def.rb', line 94

def code_lists
  children.map(&:code_lists).inject(&:|)
end

- (LoopDef) copy(changes = {})



48
49
50
51
52
53
54
55
56
# File 'lib/stupidedi/schema/loop_def.rb', line 48

def copy(changes = {})
  LoopDef.new \
    changes.fetch(:id, @id),
    changes.fetch(:repeat_count, @repeat_count),
    changes.fetch(:header_segment_uses, @header_segment_uses),
    changes.fetch(:loop_defs, @loop_defs),
    changes.fetch(:trailer_segment_uses, @trailer_segment_uses),
    changes.fetch(:parent, @parent)
end

- (LoopVal) empty



85
86
87
# File 'lib/stupidedi/schema/loop_def.rb', line 85

def empty
  Values::LoopVal.new(self, [])
end

- (SegmentUse) entry_segment_use



75
76
77
# File 'lib/stupidedi/schema/loop_def.rb', line 75

def entry_segment_use
  @header_segment_uses.head
end

- (Boolean) hierarchical?

See Also:

  • 5.6 HL-initiated Loop


70
71
72
# File 'lib/stupidedi/schema/loop_def.rb', line 70

def hierarchical?
  @header_segment_uses.head.definition.id == :HL
end

- (Boolean) loop?



89
90
91
# File 'lib/stupidedi/schema/loop_def.rb', line 89

def loop?
  true
end

- pretty_print(q)



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/stupidedi/schema/loop_def.rb', line 99

def pretty_print(q)
  q.text("LoopDef[#{@id}]")
  q.group(2, "(", ")") do
    q.breakable ""
    @header_segment_uses.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
    @loop_defs.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
    @trailer_segment_uses.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
  end
end

- (Boolean) repeatable?



58
59
60
# File 'lib/stupidedi/schema/loop_def.rb', line 58

def repeatable?
  @repeat_count.try{|r| r.include?(2) }
end