Class: NdrImport::Xml::ColumnMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/ndr_import/xml/column_mapping.rb

Overview

This class generates new XML column mappings where repeating columns/sections have been identified in the xml. This avoids the need for mappings to verbosly define repeating columns/sections

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(existing_column, unmapped_node_parts, klass_increment, xml_line, klass) ⇒ ColumnMapping

Returns a new instance of ColumnMapping.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ndr_import/xml/column_mapping.rb', line 10

def initialize(existing_column, unmapped_node_parts, klass_increment, xml_line, klass)
  @existing_column      = existing_column
  @unmapped_node_parts  = unmapped_node_parts
  @klass_increment      = klass_increment
  @xml_line             = xml_line
  @klass                = klass
  @repeating_item       = existing_column.dig('xml_cell', 'multiple')
  @increment_field_name = existing_column.dig('xml_cell', 'increment_field_name')
  @build_new_record     = existing_column.dig('xml_cell', 'build_new_record')
  @klass_section_xpath  = existing_column.dig('xml_cell', 'klass_section')
end

Instance Attribute Details

#build_new_recordObject

Returns the value of attribute build_new_record.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def build_new_record
  @build_new_record
end

#existing_columnObject

Returns the value of attribute existing_column.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def existing_column
  @existing_column
end

#increment_field_nameObject

Returns the value of attribute increment_field_name.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def increment_field_name
  @increment_field_name
end

#klassObject

Returns the value of attribute klass.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def klass
  @klass
end

#klass_incrementObject

Returns the value of attribute klass_increment.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def klass_increment
  @klass_increment
end

#klass_section_xpathObject

Returns the value of attribute klass_section_xpath.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def klass_section_xpath
  @klass_section_xpath
end

#repeating_itemObject

Returns the value of attribute repeating_item.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def repeating_item
  @repeating_item
end

#unmapped_node_partsObject

Returns the value of attribute unmapped_node_parts.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def unmapped_node_parts
  @unmapped_node_parts
end

#xml_lineObject

Returns the value of attribute xml_line.



7
8
9
# File 'lib/ndr_import/xml/column_mapping.rb', line 7

def xml_line
  @xml_line
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ndr_import/xml/column_mapping.rb', line 22

def call
  new_column                              = existing_column.deep_dup
  new_column['column']                    = unmapped_node_parts[:column_name]
  new_column['xml_cell']['relative_path'] = unmapped_node_parts[:column_relative_path]

  # create unique rawtext names for repeating sections within a record
  apply_new_rawtext_and_mapped_names_to(new_column) if repeating_item

  return new_column unless incremented_klass_needed?

  new_column['klass'] = incremented_klass
  new_column
end