Module: ComponentDescriptors::DSL

Includes:
OptionsParser
Defined in:
lib/component_descriptors.rb

Overview

These methods can be used to construct nested descriptors.

repeating_section :insurance_provider => %qhref="cda:templateId/@root='2.16.840.1.113883.10.20.1.26'">entryRelationship/cda:act do

field :group_number => %q{cda:id/@root}, :required => false
section :insurance_type => %q{cda:code[@codeSystem='2.16.840.1.113883.6.255.1336']}, :required => false do
  attribute :code
  field :name => %q{@displayName}
end
field :represented_organization => %q{cda:performer[@typeCode='PRF']/cda:assignedEntity[@classCode='ASSIGNED']/cda:representedOrganization[@classCode='ORG']/cda:name}, :required => false

end

Constant Summary

Constant Summary

Constants included from OptionsParser

OptionsParser::KNOWN_KEYS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_args

Class Method Details

.create(type, key, locator, options, &descriptors) ⇒ Object

Factory creation method for descriptors of :type.



238
239
240
# File 'lib/component_descriptors.rb', line 238

def self.create(type, key, locator, options, &descriptors)
  "ComponentDescriptors::#{type.to_s.classify}".constantize.send(:new, key, locator, options, &descriptors)
end

Instance Method Details

#attribute(*args) ⇒ Object

Shortcut for adding a field whose xpath locator is simply the key value as an attribute of the current node (“@#key”).



226
227
228
# File 'lib/component_descriptors.rb', line 226

def attribute(*args)
  _instantiate_and_store(:field, args, :locate_by => :attribute)
end

#field(*args) ⇒ Object

Adds a field with a single value in the document.



220
221
222
# File 'lib/component_descriptors.rb', line 220

def field(*args)
  _instantiate_and_store(:field, *args)
end

#mapping(key) ⇒ Object

Accessor for descriptors in our original ComponentDescriptor::Mapping. Used to lookup references to common descriptors when instantiating. Raises a DescriptorError if mapping_class is not set or descriptor cannot be found.

Raises:



203
204
205
206
207
# File 'lib/component_descriptors.rb', line 203

def mapping(key)
  raise(DescriptorError, "No Mapping class set.") unless mapping_class
#      pp mapping_class
  common_descriptor = mapping_class.get_common(key)
end

#mapping_classObject



193
194
195
196
197
# File 'lib/component_descriptors.rb', line 193

def mapping_class
  mapping_class = @mapping_class
  mapping_class ||= parent.try(:mapping_class) if respond_to?(:parent)
  return mapping_class
end

#mapping_class=(mapping_class) ⇒ Object

Set a local reference to a ComponentDescriptors::Mapping.



189
190
191
# File 'lib/component_descriptors.rb', line 189

def mapping_class=(mapping_class)
  @mapping_class = mapping_class 
end

#reference(key) ⇒ Object

Evaluates the descriptors of a common descriptor section used by multiple components.



232
233
234
235
# File 'lib/component_descriptors.rb', line 232

def reference(key)
  descriptors = mapping(key).descriptors
  instance_eval(&descriptors)
end

#repeating_section(*args, &descriptors) ⇒ Object

Adds a repeating section which occurs one or more times.



215
216
217
# File 'lib/component_descriptors.rb', line 215

def repeating_section(*args, &descriptors)
  _instantiate_and_store(:repeating_section, *args, &descriptors)
end

#section(*args, &descriptors) ⇒ Object

Adds a subsection to this section.



210
211
212
# File 'lib/component_descriptors.rb', line 210

def section(*args, &descriptors)
  _instantiate_and_store(:section, *args, &descriptors)
end