Class: Stupidedi::Schema::CompositeElementDef

Inherits:
AbstractElementDef show all
Defined in:
lib/stupidedi/schema/element_def.rb

Overview

See Also:

  • B.1.1.3.3 Composite Data Structure

Instance Attribute Summary collapse

Attributes inherited from AbstractElementDef

#description, #id, #name

Constructors collapse

Instance Method Summary collapse

Methods inherited from AbstractElementDef

#element?

Methods included from Inspect

#inspect

Methods inherited from AbstractDef

#component?, #definition?, #element?, #functional_group?, #interchange?, #loop?, #repeated?, #segment?, #table?, #transaction_set?, #usage?

Constructor Details

#initialize(id, name, description, component_uses, syntax_notes, parent) ⇒ CompositeElementDef



90
91
92
93
94
95
96
97
98
99
# File 'lib/stupidedi/schema/element_def.rb', line 90

def initialize(id, name, description, component_uses, syntax_notes, parent)
  @id, @name, @description, @component_uses, @syntax_notes, @parent =
    id, name, description, component_uses, syntax_notes, parent

  # Delay re-parenting until the entire definition tree has a root
  # to prevent unnecessarily copying objects
  unless parent.nil?
    @component_uses = @component_uses.map{|x| x.copy(:parent => self) }
  end
end

Instance Attribute Details

#component_usesArray<ComponentElementUse> (readonly)



82
83
84
# File 'lib/stupidedi/schema/element_def.rb', line 82

def component_uses
  @component_uses
end

#parentCompositeElementUse (readonly)



88
89
90
# File 'lib/stupidedi/schema/element_def.rb', line 88

def parent
  @parent
end

#syntax_notesArray<SyntaxNote> (readonly)



85
86
87
# File 'lib/stupidedi/schema/element_def.rb', line 85

def syntax_notes
  @syntax_notes
end

Class Method Details

.build(id, name, description, *args) ⇒ CompositeElementDef



163
164
165
166
167
168
# File 'lib/stupidedi/schema/element_def.rb', line 163

def build(id, name, description, *args)
  component_uses = args.take_while{|x| x.is_a?(AbstractElementUse) }
  syntax_notes   = args.drop(component_uses.length)

  new(id, name, description, component_uses, syntax_notes, nil)
end

Instance Method Details

#code_listsAbstractSet<CodeList>



138
139
140
# File 'lib/stupidedi/schema/element_def.rb', line 138

def code_lists
  @component_uses.map(&:code_lists).inject(&:|)
end

#composite?Boolean



118
119
120
# File 'lib/stupidedi/schema/element_def.rb', line 118

def composite?
  true
end

#copy(changes = {}) ⇒ CompositeElementDef



102
103
104
105
106
107
108
109
110
# File 'lib/stupidedi/schema/element_def.rb', line 102

def copy(changes = {})
  CompositeElementDef.new \
    changes.fetch(:id, @id),
    changes.fetch(:name, @name),
    changes.fetch(:description, @description),
    changes.fetch(:component_uses, @component_uses),
    changes.fetch(:syntax_notes, @syntax_notes),
    changes.fetch(:parent, @parent)
end

#empty(usage, position) ⇒ CompositeElementVal



133
134
135
# File 'lib/stupidedi/schema/element_def.rb', line 133

def empty(usage, position)
  Values::CompositeElementVal.new([], usage)
end

#pretty_print(q)



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/stupidedi/schema/element_def.rb', line 143

def pretty_print(q)
  q.text("CompositeElementDef[#{@id}]")
  q.group(2, "(", ")") do
    q.breakable ""
    @component_uses.each do |e|
      unless q.current_group.first?
        q.text ","
        q.breakable
      end
      q.pp e
    end
  end
end

#simple?Boolean



113
114
115
# File 'lib/stupidedi/schema/element_def.rb', line 113

def simple?
  false
end

#simple_use(requirement, repeat_count, parent = nil) ⇒ CompositeElementUse



123
124
125
# File 'lib/stupidedi/schema/element_def.rb', line 123

def simple_use(requirement, repeat_count, parent = nil)
  CompositeElementUse.new(self, requirement, repeat_count, parent)
end

#value(component_vals, usage, position) ⇒ CompositeElementVal



128
129
130
# File 'lib/stupidedi/schema/element_def.rb', line 128

def value(component_vals, usage, position)
  Values::CompositeElementVal.new(component_vals, usage)
end