Class: NdrImport::Xml::Table

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

Overview

This class maintains the state of a xml table mapping and encapsulates the logic required to transform a table of data into “records”. Particular attention has been made to use enumerables throughout to help with the transformation of large quantities of data.

Instance Attribute Summary

Attributes inherited from Table

#notifier

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Table

#all_valid_options, #encode_with, #header_valid?, #initialize, #match, #process_line, #transform

Constructor Details

This class inherits a constructor from NdrImport::Table

Class Method Details

.all_valid_optionsObject



10
11
12
# File 'lib/ndr_import/xml/table.rb', line 10

def self.all_valid_options
  super - %w[delimiter header_lines footer_lines]
end

Instance Method Details



18
19
20
# File 'lib/ndr_import/xml/table.rb', line 18

def footer_lines
  0
end

#header_linesObject



14
15
16
# File 'lib/ndr_import/xml/table.rb', line 14

def header_lines
  0
end

#transform_line(line, index) ⇒ Object

This method transforms an incoming line (element) of xml data by applying each of the klass masked mappings to the line and yielding the klass and fields for each mapped klass.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ndr_import/xml/table.rb', line 25

def transform_line(line, index)
  return enum_for(:transform_line, line, index) unless block_given?

  raise 'Not an Nokogiri::XML::Element!' unless line.is_a? Nokogiri::XML::Element

  validate_column_mappings(line)

  xml_line = column_xpaths.map { |column_xpath| line.xpath(column_xpath).inner_text }

  masked_mappings.each do |klass, klass_mappings|
    fields = mapped_line(xml_line, klass_mappings)
    next if fields[:skip].to_s == 'true'.freeze
    yield(klass, fields, index)
  end
end