Class: NdrImport::Xml::Table
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.
Constant Summary collapse
- XML_OPTIONS =
%w[pattern_match_record_xpath xml_record_xpath yield_xml_record].freeze
Instance Attribute Summary
Attributes inherited from Table
Class Method Summary collapse
Instance Method Summary collapse
- #footer_lines ⇒ Object
- #header_lines ⇒ Object
-
#transform_line(line, index) {|records_from_xml_line.compact| ... } ⇒ 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.
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_options ⇒ Object
15 16 17 |
# File 'lib/ndr_import/xml/table.rb', line 15 def self. super - %w[delimiter header_lines footer_lines] + XML_OPTIONS end |
Instance Method Details
#footer_lines ⇒ Object
25 26 27 |
# File 'lib/ndr_import/xml/table.rb', line 25 def 0 end |
#header_lines ⇒ Object
21 22 23 |
# File 'lib/ndr_import/xml/table.rb', line 21 def header_lines 0 end |
#transform_line(line, index) {|records_from_xml_line.compact| ... } ⇒ 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.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ndr_import/xml/table.rb', line 32 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 augmented_masked_mappings = augment_and_validate_column_mappings_for(line) xml_line = xml_line_from(line) records_from_xml_line = [] augmented_masked_mappings.each do |klass, klass_mappings| fields = mapped_line(xml_line, klass_mappings) next if fields[:skip].to_s == 'true'.freeze if yield_xml_record records_from_xml_line << [klass, fields, index] else yield(klass, fields, index) end end yield(records_from_xml_line.compact) if yield_xml_record end |