Class: NdrImport::PdfForm::Table
- Defined in:
- lib/ndr_import/pdf_form/table.rb
Overview
This class maintains the state of a PDF form 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
Class Method Summary collapse
Instance Method Summary collapse
- #footer_lines ⇒ Object
- #format ⇒ Object
- #header_lines ⇒ Object
-
#transform_line(line, index) ⇒ Object
This method transforms an incoming line (Hash) of data.
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
10 11 12 |
# File 'lib/ndr_import/pdf_form/table.rb', line 10 def self. super - %w[delimiter footer_lines format header_lines] end |
Instance Method Details
#footer_lines ⇒ Object
14 15 16 |
# File 'lib/ndr_import/pdf_form/table.rb', line 14 def 0 end |
#format ⇒ Object
18 19 20 |
# File 'lib/ndr_import/pdf_form/table.rb', line 18 def format 'acroform' end |
#header_lines ⇒ Object
22 23 24 |
# File 'lib/ndr_import/pdf_form/table.rb', line 22 def header_lines 0 end |
#transform_line(line, index) ⇒ Object
This method transforms an incoming line (Hash) of data. Each of the klass masked mappings are applied to the hash values, which are reordered by the mappng definition, yielding the klass and fields for each mapped klass.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ndr_import/pdf_form/table.rb', line 29 def transform_line(line, index) return enum_for(:transform_line, line, index) unless block_given? raise 'NdrImport::PdfForm::Table expects a Hash!' unless line.is_a? Hash validate_column_mappings(line) masked_mappings.each do |klass, klass_mappings| ordered_line = order_values_by_mappings(line, klass_mappings) fields = mapped_line(ordered_line, klass_mappings) next if fields[:skip].to_s == 'true'.freeze yield(klass, fields, index) end end |