Module: NcsNavigator::Warehouse::Models::MdesModel

Defined in:
lib/ncs_navigator/warehouse/models/mdes_model.rb

Overview

A mix-in providing special functionality for MDES-based DataMapper models.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#write_mdes_xml(io, options = {})

This method returns an undefined value.

Writes an XML fragment for this model to the given IO stream.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ncs_navigator/warehouse/models/mdes_model.rb', line 16

def write_mdes_xml(io, options={})
  builder = Builder::XmlMarkup.new(
    :indent => options[:indent] || 2, :margin => options[:margin])
  io << builder.tag!(self.class.mdes_table_name) { |xml|
    self.class.mdes_order.each do |variable_name|
      prop = self.class.properties[variable_name]

      is_hidden_pii = !options[:pii] && prop.pii == true
      content =
        unless is_hidden_pii
          self.send(variable_name)
        end
      if !content && prop.options[:set]
        content = %w(-3 -6).detect { |c| prop.options[:set].include?(c) }
      end

      # Omit if blank and omittable, otherwise have a blast
      if !content.blank? || !prop.omittable
        xml.tag!(variable_name, content)
      end
    end

    xml.transaction_type(:'xsi:nil' => true)
  } << "\n"
end