Class: Stupidedi::Schema::TableDef
- Inherits:
-
AbstractDef
- Object
- AbstractDef
- Stupidedi::Schema::TableDef
- Defined in:
- lib/stupidedi/schema/table_def.rb
Instance Attribute Summary collapse
- #header_segment_uses ⇒ Array<SegmentUse> readonly
- #id ⇒ String readonly
- #loop_defs ⇒ Array<LoopDef> readonly
- #parent ⇒ TransactionSetDef readonly
- #position ⇒ Integer readonly
- #trailer_segment_uses ⇒ Array<SegmentUse> readonly
Constructors collapse
- .detail(id, *children) ⇒ TableDef
- .header(id, *children) ⇒ TableDef
- .summary(id, *children) ⇒ TableDef
Instance Method Summary collapse
- #children ⇒ Array<SegmentUse, LoopDef>
- #code_lists ⇒ AbstractSet<CodeList>
- #copy(changes = {}) ⇒ TableDef
- #empty ⇒ Values::TableVal
- #entry_segment_uses ⇒ Array<SegmentUse>
-
#initialize(id, position, repeatable, header_segment_uses, loop_defs, trailer_segment_uses, parent) ⇒ TableDef
constructor
A new instance of TableDef.
- #pretty_print(q) ⇒ void
- #repeatable? ⇒ Boolean
- #table? ⇒ Boolean
Methods inherited from AbstractDef
#component?, #composite?, #definition?, #element?, #functional_group?, #interchange?, #loop?, #repeated?, #segment?, #simple?, #transaction_set?, #usage?
Constructor Details
#initialize(id, position, repeatable, header_segment_uses, loop_defs, trailer_segment_uses, parent) ⇒ TableDef
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/stupidedi/schema/table_def.rb', line 27 def initialize(id, position, repeatable, header_segment_uses, loop_defs, trailer_segment_uses, parent) @id, @position, @repeatable, @header_segment_uses, @loop_defs, @trailer_segment_uses, @parent = id, position, repeatable, 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
#header_segment_uses ⇒ Array<SegmentUse> (readonly)
13 14 15 |
# File 'lib/stupidedi/schema/table_def.rb', line 13 def header_segment_uses @header_segment_uses end |
#id ⇒ String (readonly)
10 11 12 |
# File 'lib/stupidedi/schema/table_def.rb', line 10 def id @id end |
#loop_defs ⇒ Array<LoopDef> (readonly)
19 20 21 |
# File 'lib/stupidedi/schema/table_def.rb', line 19 def loop_defs @loop_defs end |
#parent ⇒ TransactionSetDef (readonly)
22 23 24 |
# File 'lib/stupidedi/schema/table_def.rb', line 22 def parent @parent end |
#position ⇒ Integer (readonly)
25 26 27 |
# File 'lib/stupidedi/schema/table_def.rb', line 25 def position @position end |
#trailer_segment_uses ⇒ Array<SegmentUse> (readonly)
16 17 18 |
# File 'lib/stupidedi/schema/table_def.rb', line 16 def trailer_segment_uses @trailer_segment_uses end |
Class Method Details
.detail(id, *children) ⇒ TableDef
129 130 131 132 133 |
# File 'lib/stupidedi/schema/table_def.rb', line 129 def detail(id, *children) header, children = children.split_when{|x| x.is_a?(LoopDef) } loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) } new(id, 2, true, header, loop_defs, trailer, nil) end |
.header(id, *children) ⇒ TableDef
122 123 124 125 126 |
# File 'lib/stupidedi/schema/table_def.rb', line 122 def header(id, *children) header, children = children.split_when{|x| x.is_a?(LoopDef) } loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) } new(id, 1, false, header, loop_defs, trailer, nil) end |
.summary(id, *children) ⇒ TableDef
136 137 138 139 140 |
# File 'lib/stupidedi/schema/table_def.rb', line 136 def summary(id, *children) header, children = children.split_when{|x| x.is_a?(LoopDef) } loop_defs, trailer = children.split_when{|x| x.is_a?(SegmentUse) } new(id, 3, false, header, loop_defs, trailer, nil) end |
Instance Method Details
#children ⇒ Array<SegmentUse, LoopDef>
69 70 71 |
# File 'lib/stupidedi/schema/table_def.rb', line 69 def children @header_segment_uses + @loop_defs + @trailer_segment_uses end |
#code_lists ⇒ AbstractSet<CodeList>
83 84 85 |
# File 'lib/stupidedi/schema/table_def.rb', line 83 def code_lists children.map(&:code_lists).inject(&:|) end |
#copy(changes = {}) ⇒ TableDef
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/stupidedi/schema/table_def.rb', line 41 def copy(changes = {}) TableDef.new \ changes.fetch(:id, @id), changes.fetch(:position, @position), changes.fetch(:repeatable, @repeatable), 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 |
#empty ⇒ Values::TableVal
74 75 76 |
# File 'lib/stupidedi/schema/table_def.rb', line 74 def empty Values::TableVal.new(self, []) end |
#entry_segment_uses ⇒ Array<SegmentUse>
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/stupidedi/schema/table_def.rb', line 57 def entry_segment_uses uses = [] uses.concat(@header_segment_uses) uses.concat(@loop_defs.map{|l| l.entry_segment_use }) uses.concat(@trailer_segment_uses) # Up to and including the first required segment opt, req = uses.split_until(&:optional?) opt.concat(req.take(1)) end |
#pretty_print(q) ⇒ void
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/stupidedi/schema/table_def.rb', line 88 def pretty_print(q) q.text("TableDef[#{@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
52 53 54 |
# File 'lib/stupidedi/schema/table_def.rb', line 52 def repeatable? @repeatable end |
#table? ⇒ Boolean
78 79 80 |
# File 'lib/stupidedi/schema/table_def.rb', line 78 def table? true end |