Class: NdrImport::NonTabular::Table
- Inherits:
-
Table
- Object
- Table
- NdrImport::NonTabular::Table
show all
- Includes:
- UTF8Encoding
- Defined in:
- lib/ndr_import/non_tabular/table.rb
Overview
This class maintains the state of a non tabular 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
- TABULAR_ONLY_OPTIONS =
%w[delimiter last_data_column liberal_parsing tablename_pattern
header_lines footer_lines xml_record_xpath slurp].freeze
- NON_TABULAR_OPTIONS =
%w[capture_end_line capture_start_line start_line_pattern
end_line_pattern remove_lines start_in_a_record
end_in_a_record].freeze
Instance Attribute Summary collapse
Attributes inherited from Table
#notifier
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Table
#all_valid_options, #encode_with, #header_valid?, #match, #process_line, #transform_line
Constructor Details
#initialize(options = {}) ⇒ Table
Returns a new instance of Table.
41
42
43
44
45
|
# File 'lib/ndr_import/non_tabular/table.rb', line 41
def initialize(options = {})
super(options)
validate_presence_of_start_line_pattern
end
|
Instance Attribute Details
#non_tabular_lines ⇒ Object
Returns the value of attribute non_tabular_lines.
31
32
33
|
# File 'lib/ndr_import/non_tabular/table.rb', line 31
def non_tabular_lines
@non_tabular_lines
end
|
Class Method Details
.all_valid_options ⇒ Object
Instance Method Details
37
38
39
|
# File 'lib/ndr_import/non_tabular/table.rb', line 37
def
0
end
|
33
34
35
|
# File 'lib/ndr_import/non_tabular/table.rb', line 33
def
0
end
|
#tablename_pattern=(_value) ⇒ Object
47
48
49
|
# File 'lib/ndr_import/non_tabular/table.rb', line 47
def tablename_pattern=(_value)
fail NdrImport::MappingError, 'Should not define tablename_pattern'
end
|
This method transforms a table of data, given a line array/enumerator and yields klass, fields and index (input row number) for each record that it would create as a result of the transformation process.
60
61
62
63
64
65
66
67
|
# File 'lib/ndr_import/non_tabular/table.rb', line 60
def transform(lines, &block)
return enum_for(:transform, lines) unless block
self.non_tabular_lines = ensure_utf8_enum!(lines)
remove_unwanted_lines
super(read_non_tabular_array, &block)
end
|
69
70
71
|
# File 'lib/ndr_import/non_tabular/table.rb', line 69
def (_line, _column_mappings)
@header_valid = true
end
|
#validate_presence_of_start_line_pattern ⇒ Object
51
52
53
54
55
|
# File 'lib/ndr_import/non_tabular/table.rb', line 51
def validate_presence_of_start_line_pattern
return if @start_line_pattern
fail NdrImport::MappingError,
I18n.t('mapping.errors.missing_start_line_pattern')
end
|