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?, #segment?, #simple?, #table?, #transaction_set?, #usage?
Constructor Details
#initialize(id, repeat_count, header_segment_uses, loop_defs, trailer_segment_uses, parent) ⇒ LoopDef
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/stupidedi/schema/loop_def.rb', line 37
def initialize(id, repeat_count, , loop_defs, trailer_segment_uses, parent)
@id, @repeat_count, , @loop_defs, @trailer_segment_uses, @parent =
id, repeat_count, , loop_defs, trailer_segment_uses, parent
unless parent.nil?
= .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
22
23
24
|
# File 'lib/stupidedi/schema/loop_def.rb', line 22
def
end
|
#id ⇒ String
16
17
18
|
# File 'lib/stupidedi/schema/loop_def.rb', line 16
def id
@id
end
|
#loop_defs ⇒ Array<LoopDef>
28
29
30
|
# File 'lib/stupidedi/schema/loop_def.rb', line 28
def loop_defs
@loop_defs
end
|
31
32
33
|
# File 'lib/stupidedi/schema/loop_def.rb', line 31
def parent
@parent
end
|
19
20
21
|
# File 'lib/stupidedi/schema/loop_def.rb', line 19
def repeat_count
@repeat_count
end
|
#trailer_segment_uses ⇒ Array<SegmentUse>
25
26
27
|
# File 'lib/stupidedi/schema/loop_def.rb', line 25
def trailer_segment_uses
@trailer_segment_uses
end
|
Class Method Details
.build(id, repeat_count, *children) ⇒ LoopDef
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/stupidedi/schema/loop_def.rb', line 136
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)
"first child must have RepeatCount.bounded(1)"
end
new(id, repeat_count, , loop_defs, trailer, nil)
end
|
Instance Method Details
#bounded? ⇒ Boolean
67
68
69
70
|
# File 'lib/stupidedi/schema/loop_def.rb', line 67
def bounded?
.head.definition.id == :LS and
@trailer_segment_uses.last.definition.id == :LE
end
|
83
84
85
|
# File 'lib/stupidedi/schema/loop_def.rb', line 83
def children
+ @loop_defs + @trailer_segment_uses
end
|
#code_lists ⇒ AbstractSet<CodeList>
97
98
99
|
# File 'lib/stupidedi/schema/loop_def.rb', line 97
def code_lists
children.map(&:code_lists).inject(&:|)
end
|
#copy(changes = {}) ⇒ LoopDef
51
52
53
54
55
56
57
58
59
|
# File 'lib/stupidedi/schema/loop_def.rb', line 51
def copy(changes = {})
LoopDef.new \
changes.fetch(:id, @id),
changes.fetch(:repeat_count, @repeat_count),
changes.fetch(:header_segment_uses, ),
changes.fetch(:loop_defs, @loop_defs),
changes.fetch(:trailer_segment_uses, @trailer_segment_uses),
changes.fetch(:parent, @parent)
end
|
#empty ⇒ LoopVal
88
89
90
|
# File 'lib/stupidedi/schema/loop_def.rb', line 88
def empty
Values::LoopVal.new(self, [])
end
|
#entry_segment_use ⇒ SegmentUse
78
79
80
|
# File 'lib/stupidedi/schema/loop_def.rb', line 78
def entry_segment_use
.head
end
|
#hierarchical? ⇒ Boolean
73
74
75
|
# File 'lib/stupidedi/schema/loop_def.rb', line 73
def hierarchical?
.head.definition.id == :HL
end
|
#loop? ⇒ Boolean
92
93
94
|
# File 'lib/stupidedi/schema/loop_def.rb', line 92
def loop?
true
end
|
#pretty_print(q) ⇒ void
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/stupidedi/schema/loop_def.rb', line 102
def pretty_print(q)
q.text("LoopDef[#{@id}]")
q.group(2, "(", ")") do
q.breakable ""
.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
61
62
63
|
# File 'lib/stupidedi/schema/loop_def.rb', line 61
def repeatable?
@repeat_count.try{|r| r.include?(2) }
end
|