Class: Stupidedi::Schema::SegmentDef
- Inherits:
-
AbstractDef
- Object
- AbstractDef
- Stupidedi::Schema::SegmentDef
- Includes:
- Inspect
- Defined in:
- lib/stupidedi/schema/segment_def.rb
Overview
Instance Attribute Summary collapse
- #element_uses ⇒ Array<SimpleElementUse, CompositeElementUse> readonly
- #id ⇒ Symbol readonly
- #name ⇒ String readonly
- #parent ⇒ SegmentUse readonly
- #purpose ⇒ String readonly
- #syntax_notes ⇒ Array<SyntaxNote> readonly
Constructors collapse
Instance Method Summary collapse
- #code_lists ⇒ AbstractSet<CodeList>
- #copy(changes = {}) ⇒ SegmentDef
- #empty(usage) ⇒ Values::SegmentVal
-
#initialize(id, name, purpose, element_uses, syntax_notes, parent) ⇒ SegmentDef
constructor
A new instance of SegmentDef.
- #pretty_print(q) ⇒ void
- #segment? ⇒ Boolean
- #use(position, requirement, repeat_count) ⇒ SegmentUse
- #value(element_vals, usage, position) ⇒ Object
Methods included from Inspect
Methods inherited from AbstractDef
#component?, #composite?, #definition?, #element?, #functional_group?, #interchange?, #loop?, #repeated?, #simple?, #table?, #transaction_set?, #usage?
Constructor Details
#initialize(id, name, purpose, element_uses, syntax_notes, parent) ⇒ SegmentDef
Returns a new instance of SegmentDef.
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/stupidedi/schema/segment_def.rb', line 28 def initialize(id, name, purpose, element_uses, syntax_notes, parent) @id, @name, @purpose, @element_uses, @syntax_notes, @parent = id, name, purpose, element_uses, syntax_notes, parent # Delay re-parenting until the entire definition tree has a root # to prevent unnecessarily copying objects unless parent.nil? @element_uses = @element_uses.map{|x| x.copy(:parent => self) } end end |
Instance Attribute Details
#element_uses ⇒ Array<SimpleElementUse, CompositeElementUse> (readonly)
20 21 22 |
# File 'lib/stupidedi/schema/segment_def.rb', line 20 def element_uses @element_uses end |
#id ⇒ Symbol (readonly)
11 12 13 |
# File 'lib/stupidedi/schema/segment_def.rb', line 11 def id @id end |
#name ⇒ String (readonly)
14 15 16 |
# File 'lib/stupidedi/schema/segment_def.rb', line 14 def name @name end |
#parent ⇒ SegmentUse (readonly)
26 27 28 |
# File 'lib/stupidedi/schema/segment_def.rb', line 26 def parent @parent end |
#purpose ⇒ String (readonly)
17 18 19 |
# File 'lib/stupidedi/schema/segment_def.rb', line 17 def purpose @purpose end |
#syntax_notes ⇒ Array<SyntaxNote> (readonly)
23 24 25 |
# File 'lib/stupidedi/schema/segment_def.rb', line 23 def syntax_notes @syntax_notes end |
Class Method Details
.build(id, name, purpose, *args) ⇒ SegmentDef
95 96 97 98 99 100 101 |
# File 'lib/stupidedi/schema/segment_def.rb', line 95 def build(id, name, purpose, *args) element_uses = args.take_while{|x| x.is_a?(AbstractElementUse) } syntax_notes = args.drop(element_uses.length) # @todo: Validate SyntaxNotes new(id, name, purpose, element_uses, syntax_notes, nil) end |
Instance Method Details
#code_lists ⇒ AbstractSet<CodeList>
69 70 71 |
# File 'lib/stupidedi/schema/segment_def.rb', line 69 def code_lists @element_uses.map(&:code_lists).inject(&:|) end |
#copy(changes = {}) ⇒ SegmentDef
40 41 42 43 44 45 46 47 48 |
# File 'lib/stupidedi/schema/segment_def.rb', line 40 def copy(changes = {}) SegmentDef.new \ changes.fetch(:id, @id), changes.fetch(:name, @name), changes.fetch(:purpose, @purpose), changes.fetch(:element_uses, @element_uses), changes.fetch(:syntax_notes, @syntax_notes), changes.fetch(:parent, @parent) end |
#empty(usage) ⇒ Values::SegmentVal
56 57 58 |
# File 'lib/stupidedi/schema/segment_def.rb', line 56 def empty(usage) Values::SegmentVal.new([], usage) end |
#pretty_print(q) ⇒ void
This method returns an undefined value.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/stupidedi/schema/segment_def.rb', line 74 def pretty_print(q) q.text "SegmentDef[#{@id}]" q.group(2, "(", ")") do q.breakable "" @element_uses.each do |e| unless q.current_group.first? q.text "," q.breakable end q.pp e end end end |
#segment? ⇒ Boolean
64 65 66 |
# File 'lib/stupidedi/schema/segment_def.rb', line 64 def segment? true end |
#use(position, requirement, repeat_count) ⇒ SegmentUse
51 52 53 |
# File 'lib/stupidedi/schema/segment_def.rb', line 51 def use(position, requirement, repeat_count) SegmentUse.new(self, position, requirement, repeat_count, nil) end |
#value(element_vals, usage, position) ⇒ Object
60 61 62 |
# File 'lib/stupidedi/schema/segment_def.rb', line 60 def value(element_vals, usage, position) Values::SegmentVal.new(element_vals, usage, position) end |