Class: Cda::XmlBuilder
- Inherits:
-
Object
- Object
- Cda::XmlBuilder
- Includes:
- Helpers
- Defined in:
- lib/cda/xml_builder.rb
Defined Under Namespace
Modules: Helpers
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#template_type ⇒ Object
readonly
Returns the value of attribute template_type.
-
#xml ⇒ Object
Returns the value of attribute xml.
Instance Method Summary collapse
- #build ⇒ Object
- #build_document ⇒ Object
-
#initialize(model, template_type = model.class.template_type) ⇒ XmlBuilder
constructor
A new instance of XmlBuilder.
- #node(name, *args, &block) ⇒ Object
Methods included from Helpers
#apply_format, #auto_format, #determine_format, #format_array, #format_date, #format_datetime, #format_human_date, #format_human_datetime
Constructor Details
#initialize(model, template_type = model.class.template_type) ⇒ XmlBuilder
Returns a new instance of XmlBuilder.
54 55 56 57 |
# File 'lib/cda/xml_builder.rb', line 54 def initialize(model, template_type = model.class.template_type) @model = model @template_type = template_type end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
2 3 4 |
# File 'lib/cda/xml_builder.rb', line 2 def model @model end |
#template_type ⇒ Object (readonly)
Returns the value of attribute template_type.
2 3 4 |
# File 'lib/cda/xml_builder.rb', line 2 def template_type @template_type end |
#xml ⇒ Object
Returns the value of attribute xml.
3 4 5 |
# File 'lib/cda/xml_builder.rb', line 3 def xml @xml end |
Instance Method Details
#build ⇒ Object
59 60 61 |
# File 'lib/cda/xml_builder.rb', line 59 def build build_instance_element(template_type, model) end |
#build_document ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cda/xml_builder.rb', line 63 def build_document self.xml = Nokogiri::XML::Builder.new if template_type != 'ClinicalDocument' xml.ClinicalDocument( 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance", 'xsi:schemaLocation' => "urn:hl7-org:v3 http://xreg2.nist.gov:8080/hitspValidation/schema/cdar2c32/infrastructure/cda/C32_CDA.xsd", 'xmlns' => "urn:hl7-org:v3", 'xmlns:mif' => "urn:hl7-org:v3/mif" ) do |_| build end else build end xml.doc end |
#node(name, *args, &block) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cda/xml_builder.rb', line 80 def node(name, *args, &block) opts = args. args << opts.each_with_object({}) do |pair, result| key, value = pair result[key.to_s.camelize(:lower)] = value unless value.blank? end tag_name = name.to_s tag_name = tag_name[0] + tag_name[1..-1].camelize(:lower) tag_name = "#{tag_name}_" if xml.respond_to?(tag_name) xml.send tag_name, *args, &block end |