Class: Stupidedi::Schema::TableDef
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from AbstractDef
#component?, #composite?, #definition?, #element?, #functional_group?, #interchange?, #loop?, #repeated?, #segment?, #simple?, #transaction_set?, #usage?
Constructor Details
#initialize(id, position, header_segment_uses, loop_defs, trailer_segment_uses, parent) ⇒ TableDef
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/stupidedi/schema/table_def.rb', line 25
def initialize(id, position, , loop_defs, trailer_segment_uses, parent)
@id, @position, , @loop_defs, @trailer_segment_uses, @parent =
id, position, , 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
11
12
13
|
# File 'lib/stupidedi/schema/table_def.rb', line 11
def
end
|
#id ⇒ String
8
9
10
|
# File 'lib/stupidedi/schema/table_def.rb', line 8
def id
@id
end
|
#loop_defs ⇒ Array<LoopDef>
17
18
19
|
# File 'lib/stupidedi/schema/table_def.rb', line 17
def loop_defs
@loop_defs
end
|
20
21
22
|
# File 'lib/stupidedi/schema/table_def.rb', line 20
def parent
@parent
end
|
#position ⇒ Integer
23
24
25
|
# File 'lib/stupidedi/schema/table_def.rb', line 23
def position
@position
end
|
#trailer_segment_uses ⇒ Array<SegmentUse>
14
15
16
|
# File 'lib/stupidedi/schema/table_def.rb', line 14
def trailer_segment_uses
@trailer_segment_uses
end
|
Class Method Details
.detail(id, *children) ⇒ TableDef
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/stupidedi/schema/table_def.rb', line 157
def detail(id, *children)
unless id.is_a?(String)
raise Exceptions::InvalidSchemaError,
"first argument to TableDef.detail must be a String but got #{id.inspect}"
end
, children = children.split_when{|x| x.is_a?(LoopDef) }
loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) }
new(id, 2, , loop_defs, trailer, nil)
end
|
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/stupidedi/schema/table_def.rb', line 145
def (id, *children)
unless id.is_a?(String)
raise Exceptions::InvalidSchemaError,
"first argument to TableDef.header must be a String but got #{id.inspect}"
end
, children = children.split_when{|x| x.is_a?(LoopDef) }
loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) }
new(id, 1, , loop_defs, trailer, nil)
end
|
.summary(id, *children) ⇒ TableDef
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/stupidedi/schema/table_def.rb', line 169
def summary(id, *children)
unless id.is_a?(String)
raise Exceptions::InvalidSchemaError,
"first argument to TableDef.summary must be a String but got #{id.inspect}"
end
, children = children.split_when{|x| x.is_a?(LoopDef) }
loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) }
new(id, 3, , loop_defs, trailer, nil)
end
|
Instance Method Details
92
93
94
|
# File 'lib/stupidedi/schema/table_def.rb', line 92
def children
+ @loop_defs + @trailer_segment_uses
end
|
#code_lists ⇒ AbstractSet<CodeList>
106
107
108
|
# File 'lib/stupidedi/schema/table_def.rb', line 106
def code_lists
children.map(&:code_lists).inject(&:|)
end
|
#copy(changes = {}) ⇒ TableDef
39
40
41
42
43
44
45
46
47
|
# File 'lib/stupidedi/schema/table_def.rb', line 39
def copy(changes = {})
TableDef.new \
changes.fetch(:id, @id),
changes.fetch(:position, @position),
changes.fetch(:header_segment_uses, ),
changes.fetch(:loop_defs, @loop_defs),
changes.fetch(:trailer_segment_uses, @trailer_segment_uses),
changes.fetch(:parent, @parent)
end
|
#descriptor ⇒ String
50
51
52
|
# File 'lib/stupidedi/schema/table_def.rb', line 50
def descriptor
"table #{id}"
end
|
97
98
99
|
# File 'lib/stupidedi/schema/table_def.rb', line 97
def empty
Values::TableVal.new(self, [])
end
|
#entry_segment_uses ⇒ Array<SegmentUse>
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/stupidedi/schema/table_def.rb', line 73
def entry_segment_uses
uses = \
+ @loop_defs.map{|l| l.entry_segment_use } \
+ @trailer_segment_uses
suffix = uses.drop_while(&:optional?)
if suffix.present?
position = suffix.map(&:position).min
uses.take_while{|u| u.position <= position }
else
uses
end
end
|
#pretty_print(q) ⇒ void
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/stupidedi/schema/table_def.rb', line 111
def pretty_print(q)
q.text("TableDef[#{@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
|
#repeat_count ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/stupidedi/schema/table_def.rb', line 60
def repeat_count
if repeatable?
RepeatCount.unbounded
else
RepeatCount.bounded(1)
end
end
|
#repeatable? ⇒ Boolean
54
55
56
57
58
|
# File 'lib/stupidedi/schema/table_def.rb', line 54
def repeatable?
.empty? and
@loop_defs.present? and
@loop_defs.head.repeatable?
end
|
#required? ⇒ Boolean
68
69
70
|
# File 'lib/stupidedi/schema/table_def.rb', line 68
def required?
entry_segment_uses.any?(&:required?)
end
|
#table? ⇒ Boolean
101
102
103
|
# File 'lib/stupidedi/schema/table_def.rb', line 101
def table?
true
end
|