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, children, parent) ⇒ LoopDef
Returns a new instance of LoopDef.
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/stupidedi/schema/loop_def.rb', line 29
def initialize(id, repeat_count, children, parent)
@id, @repeat_count, @children, @parent =
id, repeat_count, children, parent
unless parent.nil?
@children = @children.map{|x| x.copy(:parent => self) }
end
end
|
Instance Attribute Details
20
21
22
|
# File 'lib/stupidedi/schema/loop_def.rb', line 20
def children
@children
end
|
#id ⇒ String
14
15
16
|
# File 'lib/stupidedi/schema/loop_def.rb', line 14
def id
@id
end
|
23
24
25
|
# File 'lib/stupidedi/schema/loop_def.rb', line 23
def parent
@parent
end
|
17
18
19
|
# File 'lib/stupidedi/schema/loop_def.rb', line 17
def repeat_count
@repeat_count
end
|
Class Method Details
.build(id, repeat_count, *children) ⇒ LoopDef
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/stupidedi/schema/loop_def.rb', line 139
def build(id, repeat_count, *children)
if children.empty? || !children.head.is_a?(SegmentUse)
raise Exceptions::InvalidSchemaError,
"first child must be a SegmentUse"
elsif children.head.repeat_count.include?(2)
raise Exceptions::InvalidSchemaError,
"first child must have RepeatCount.bounded(1)"
end
new(id, repeat_count, children, nil)
end
|
Instance Method Details
#bounded? ⇒ Boolean
85
86
87
88
89
90
91
|
# File 'lib/stupidedi/schema/loop_def.rb', line 85
def bounded?
first_seg = @children.find{|x| x.is_a?(SegmentUse) }
last_seg = @children.reverse.find{|x| x.is_a?(SegmentUse) }
first_seg && last_seg &&
first_seg.definition.id == :LS &&
last_seg.definition.id == :LE
end
|
#code_lists ⇒ AbstractSet<CodeList>
114
115
116
|
# File 'lib/stupidedi/schema/loop_def.rb', line 114
def code_lists
@children.map(&:code_lists).inject(&:|)
end
|
#copy(changes = {}) ⇒ LoopDef
41
42
43
44
45
46
47
|
# File 'lib/stupidedi/schema/loop_def.rb', line 41
def copy(changes = {})
LoopDef.new \
changes.fetch(:id, @id),
changes.fetch(:repeat_count, @repeat_count),
changes.fetch(:children, @children),
changes.fetch(:parent, @parent)
end
|
#descriptor ⇒ String
75
76
77
|
# File 'lib/stupidedi/schema/loop_def.rb', line 75
def descriptor
"loop #{id}"
end
|
#empty ⇒ LoopVal
105
106
107
|
# File 'lib/stupidedi/schema/loop_def.rb', line 105
def empty
Values::LoopVal.new(self, [])
end
|
#entry_segment_use ⇒ SegmentUse
100
101
102
|
# File 'lib/stupidedi/schema/loop_def.rb', line 100
def entry_segment_use
@children.find{|x| x.is_a?(SegmentUse) }
end
|
Deprecated.
Use #children instead. This method does not include segments that appear between child loops in interleaved structures.
Returns segments before the first LoopDef.
53
54
55
|
# File 'lib/stupidedi/schema/loop_def.rb', line 53
def
@children.take_while{|x| x.is_a?(SegmentUse) }
end
|
#hierarchical? ⇒ Boolean
94
95
96
97
|
# File 'lib/stupidedi/schema/loop_def.rb', line 94
def hierarchical?
first_seg = @children.find{|x| x.is_a?(SegmentUse) }
first_seg && first_seg.definition.id == :HL
end
|
#loop? ⇒ Boolean
109
110
111
|
# File 'lib/stupidedi/schema/loop_def.rb', line 109
def loop?
true
end
|
#loop_defs ⇒ Array<LoopDef>
Deprecated.
Use #children instead and filter with ‘select{|x| x.is_a?(LoopDef)}`.
Returns all LoopDef children.
60
61
62
|
# File 'lib/stupidedi/schema/loop_def.rb', line 60
def loop_defs
@children.select{|x| x.is_a?(LoopDef) }
end
|
#pretty_print(q) ⇒ void
This method returns an undefined value.
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/stupidedi/schema/loop_def.rb', line 119
def pretty_print(q)
q.text("LoopDef[#{@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
|
#repeatable? ⇒ Boolean
79
80
81
|
# File 'lib/stupidedi/schema/loop_def.rb', line 79
def repeatable?
@repeat_count.try{|r| r.include?(2) }
end
|
#trailer_segment_uses ⇒ Array<SegmentUse>
Deprecated.
Use #children instead. This method does not include segments that appear between child loops in interleaved structures.
Returns segments after the last LoopDef.
68
69
70
71
72
|
# File 'lib/stupidedi/schema/loop_def.rb', line 68
def trailer_segment_uses
last_loop_idx = @children.rindex{|x| x.is_a?(LoopDef) }
return [] if last_loop_idx.nil?
@children.drop(last_loop_idx + 1).select{|x| x.is_a?(SegmentUse) }
end
|