Class: Stupidedi::Schema::CompositeElementDef

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

Overview

See Also:

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

- (CompositeElementDef) initialize(id, name, description, component_uses, syntax_notes, parent)

Returns a new instance of CompositeElementDef



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

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

- (Array<ComponentElementUse>) component_uses (readonly)



80
81
82
# File 'lib/stupidedi/schema/element_def.rb', line 80

def component_uses
  @component_uses
end

- (CompositeElementUse) parent (readonly)

Returns:



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

def parent
  @parent
end

- (Array<SyntaxNote>) syntax_notes (readonly)

Returns:



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

def syntax_notes
  @syntax_notes
end

Class Method Details

+ (CompositeElementDef) build(id, name, description, *args)

Returns:



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

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

- (AbstractSet<CodeList>) code_lists

Returns:



136
137
138
# File 'lib/stupidedi/schema/element_def.rb', line 136

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

- (Boolean) composite?

Returns true

Returns:

  • (Boolean)

    true



116
117
118
# File 'lib/stupidedi/schema/element_def.rb', line 116

def composite?
  true
end

- (CompositeElementDef) copy(changes = {})

Returns:



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

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

- (CompositeElementVal) empty(usage, position)

Returns:

  • (CompositeElementVal)


131
132
133
# File 'lib/stupidedi/schema/element_def.rb', line 131

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

- pretty_print(q)

This method returns an undefined value.



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

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

- (Boolean) simple?

Returns false

Returns:

  • (Boolean)

    false



111
112
113
# File 'lib/stupidedi/schema/element_def.rb', line 111

def simple?
  false
end

- (CompositeElementUse) simple_use(requirement, repeat_count, parent = nil)

Returns:



121
122
123
# File 'lib/stupidedi/schema/element_def.rb', line 121

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

- (CompositeElementVal) value(component_vals, usage, position)

Returns:

  • (CompositeElementVal)


126
127
128
# File 'lib/stupidedi/schema/element_def.rb', line 126

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