Class: Stupidedi::Schema::LoopDef
Overview
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Inspect
#inspect
Methods inherited from AbstractDef
#component?, #composite?, #definition?, #element?, #functional_group?, #interchange?, #repeated?, #required?, #segment?, #simple?, #table?, #transaction_set?, #usage?
Constructor Details
#initialize(id, repeat_count, header_segment_uses, loop_defs, trailer_segment_uses, parent) ⇒ LoopDef
Returns a new instance of LoopDef.
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/stupidedi/schema/loop_def.rb', line 35
def initialize(id, repeat_count, , loop_defs, trailer_segment_uses, parent)
@id, @repeat_count, @header_segment_uses, @loop_defs, @trailer_segment_uses, @parent =
id, repeat_count, , loop_defs, trailer_segment_uses, parent
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
20
21
22
|
# File 'lib/stupidedi/schema/loop_def.rb', line 20
def
@header_segment_uses
end
|
#id ⇒ String
14
15
16
|
# File 'lib/stupidedi/schema/loop_def.rb', line 14
def id
@id
end
|
#loop_defs ⇒ Array<LoopDef>
26
27
28
|
# File 'lib/stupidedi/schema/loop_def.rb', line 26
def loop_defs
@loop_defs
end
|
29
30
31
|
# File 'lib/stupidedi/schema/loop_def.rb', line 29
def parent
@parent
end
|
17
18
19
|
# File 'lib/stupidedi/schema/loop_def.rb', line 17
def repeat_count
@repeat_count
end
|
#trailer_segment_uses ⇒ Array<SegmentUse>
23
24
25
|
# File 'lib/stupidedi/schema/loop_def.rb', line 23
def trailer_segment_uses
@trailer_segment_uses
end
|
Class Method Details
.build(id, repeat_count, *children) ⇒ LoopDef
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/stupidedi/schema/loop_def.rb', line 139
def build(id, repeat_count, *children)
, children = children.split_when{|x| x.is_a?(LoopDef) }
loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) }
if .empty?
raise Exceptions::InvalidSchemaError,
"first child must be a SegmentUse"
elsif .head.repeat_count.include?(2)
raise Exceptions::InvalidSchemaError,
"first child must have RepeatCount.bounded(1)"
end
trailer.each.with_index do |s, k|
unless s.segment?
if s.respond_to?(:pretty_inspect)
raise Exceptions::InvalidSchemaError,
"arguments after last child LoopDef (#{loop_defs.last.id})
must be segments, but #{k+1} arguments later is not a
SegmentUse: #{s.pretty_inspect}".join
else
raise Exceptions::InvalidSchemaError,
"arguments after last child LoopDef (#{loop_defs.last.id})
must be segments, but #{k+1} arguments later is not a
SegmentUse: #{s.inspect}".join
end
end
end
new(id, repeat_count, , loop_defs, trailer, nil)
end
|
Instance Method Details
#bounded? ⇒ Boolean
70
71
72
73
|
# File 'lib/stupidedi/schema/loop_def.rb', line 70
def bounded?
@header_segment_uses.head.definition.id == :LS and
@trailer_segment_uses.last.definition.id == :LE
end
|
86
87
88
|
# File 'lib/stupidedi/schema/loop_def.rb', line 86
def children
@header_segment_uses + @loop_defs + @trailer_segment_uses
end
|
#code_lists ⇒ AbstractSet<CodeList>
100
101
102
|
# File 'lib/stupidedi/schema/loop_def.rb', line 100
def code_lists
children.map(&:code_lists).inject(&:|)
end
|
#copy(changes = {}) ⇒ LoopDef
49
50
51
52
53
54
55
56
57
|
# File 'lib/stupidedi/schema/loop_def.rb', line 49
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
|
#descriptor ⇒ String
60
61
62
|
# File 'lib/stupidedi/schema/loop_def.rb', line 60
def descriptor
"loop #{id}"
end
|
#empty ⇒ LoopVal
91
92
93
|
# File 'lib/stupidedi/schema/loop_def.rb', line 91
def empty
Values::LoopVal.new(self, [])
end
|
#entry_segment_use ⇒ SegmentUse
81
82
83
|
# File 'lib/stupidedi/schema/loop_def.rb', line 81
def entry_segment_use
@header_segment_uses.head
end
|
#hierarchical? ⇒ Boolean
76
77
78
|
# File 'lib/stupidedi/schema/loop_def.rb', line 76
def hierarchical?
@header_segment_uses.head.definition.id == :HL
end
|
#loop? ⇒ Boolean
95
96
97
|
# File 'lib/stupidedi/schema/loop_def.rb', line 95
def loop?
true
end
|
#pretty_print(q)
This method returns an undefined value.
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/stupidedi/schema/loop_def.rb', line 105
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
|
#repeatable? ⇒ Boolean
64
65
66
|
# File 'lib/stupidedi/schema/loop_def.rb', line 64
def repeatable?
@repeat_count.try{|r| r.include?(2) }
end
|