Class: Topographer::Importer::Mapper::MapperBuilder
- Inherits:
-
Object
- Object
- Topographer::Importer::Mapper::MapperBuilder
- Includes:
- MappingColumns, MappingValidator
- Defined in:
- lib/topographer/importer/mapper/mapper_builder.rb
Instance Attribute Summary collapse
-
#default_values ⇒ Object
readonly
Returns the value of attribute default_values.
-
#ignored_mappings ⇒ Object
readonly
Returns the value of attribute ignored_mappings.
-
#key_fields ⇒ Object
readonly
Returns the value of attribute key_fields.
-
#optional_mappings ⇒ Object
readonly
Returns the value of attribute optional_mappings.
-
#required_mappings ⇒ Object
readonly
Returns the value of attribute required_mappings.
-
#validation_mappings ⇒ Object
readonly
Returns the value of attribute validation_mappings.
Instance Method Summary collapse
- #default_value(output_field, &mapping_behavior) ⇒ Object
- #ignored_column(input_column) ⇒ Object
-
#initialize ⇒ MapperBuilder
constructor
A new instance of MapperBuilder.
- #key_field(output_field) ⇒ Object
- #optional_mapping(input_columns, output_field, &mapping_behavior) ⇒ Object
- #required_mapping(input_columns, output_field, &mapping_behavior) ⇒ Object
- #validation_field(name, input_columns, &mapping_behavior) ⇒ Object
Methods included from MappingValidator
#validate_key_field, #validate_unique_column_mapping_type, #validate_unique_mapping, #validate_unique_output_mapping, #validate_unique_validation_name
Methods included from MappingColumns
#default_fields, #ignored_mapping_columns, #input_columns, #optional_mapping_columns, #output_fields, #required_input_columns, #required_mapping_columns, #validation_mapping_columns
Constructor Details
#initialize ⇒ MapperBuilder
Returns a new instance of MapperBuilder.
8 9 10 11 12 13 14 15 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 8 def initialize @required_mappings = {} @optional_mappings = {} @ignored_mappings = {} @validation_mappings = {} @default_values = {} @key_fields = [] end |
Instance Attribute Details
#default_values ⇒ Object (readonly)
Returns the value of attribute default_values.
5 6 7 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 5 def default_values @default_values end |
#ignored_mappings ⇒ Object (readonly)
Returns the value of attribute ignored_mappings.
5 6 7 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 5 def ignored_mappings @ignored_mappings end |
#key_fields ⇒ Object (readonly)
Returns the value of attribute key_fields.
5 6 7 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 5 def key_fields @key_fields end |
#optional_mappings ⇒ Object (readonly)
Returns the value of attribute optional_mappings.
5 6 7 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 5 def optional_mappings @optional_mappings end |
#required_mappings ⇒ Object (readonly)
Returns the value of attribute required_mappings.
5 6 7 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 5 def required_mappings @required_mappings end |
#validation_mappings ⇒ Object (readonly)
Returns the value of attribute validation_mappings.
5 6 7 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 5 def validation_mappings @validation_mappings end |
Instance Method Details
#default_value(output_field, &mapping_behavior) ⇒ Object
32 33 34 35 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 32 def default_value(output_field, &mapping_behavior) validate_unique_mapping([], output_field) @default_values[output_field] = Topographer::Importer::Mapper::DefaultFieldMapping.new(output_field, &mapping_behavior) end |
#ignored_column(input_column) ⇒ Object
42 43 44 45 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 42 def ignored_column(input_column) validate_unique_column_mapping_type(input_column, ignored: true) @ignored_mappings[input_column] = Topographer::Importer::Mapper::IgnoredFieldMapping.new(input_column) end |
#key_field(output_field) ⇒ Object
37 38 39 40 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 37 def key_field(output_field) validate_key_field(output_field) @key_fields << output_field end |
#optional_mapping(input_columns, output_field, &mapping_behavior) ⇒ Object
22 23 24 25 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 22 def optional_mapping(input_columns, output_field, &mapping_behavior) validate_unique_mapping(input_columns, output_field) @optional_mappings[output_field] = Topographer::Importer::Mapper::FieldMapping.new(false, input_columns, output_field, &mapping_behavior) end |
#required_mapping(input_columns, output_field, &mapping_behavior) ⇒ Object
17 18 19 20 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 17 def required_mapping(input_columns, output_field, &mapping_behavior) validate_unique_mapping(input_columns, output_field) @required_mappings[output_field] = Topographer::Importer::Mapper::FieldMapping.new(true, input_columns, output_field, &mapping_behavior) end |
#validation_field(name, input_columns, &mapping_behavior) ⇒ Object
27 28 29 30 |
# File 'lib/topographer/importer/mapper/mapper_builder.rb', line 27 def validation_field(name, input_columns, &mapping_behavior) validate_unique_validation_name(name) @validation_mappings[name] = Topographer::Importer::Mapper::ValidationFieldMapping.new(name, input_columns, &mapping_behavior) end |