Class: Bulkrax::SampleCsvService::MappingManager
- Inherits:
-
Object
- Object
- Bulkrax::SampleCsvService::MappingManager
- Defined in:
- app/services/bulkrax/sample_csv_service/mapping_manager.rb
Overview
Handles loading and filtering of Bulkrax field mappings
Instance Attribute Summary collapse
-
#mappings ⇒ Object
readonly
Returns the value of attribute mappings.
Instance Method Summary collapse
- #find_by_flag(field_name, default) ⇒ Object
-
#initialize ⇒ MappingManager
constructor
A new instance of MappingManager.
- #key_to_mapped_column(key) ⇒ Object
- #mapped_to_key(column_str) ⇒ Object
- #split_value_for(mapping_key) ⇒ Object
Constructor Details
#initialize ⇒ MappingManager
Returns a new instance of MappingManager.
8 9 10 |
# File 'app/services/bulkrax/sample_csv_service/mapping_manager.rb', line 8 def initialize @mappings = load_mappings end |
Instance Attribute Details
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
6 7 8 |
# File 'app/services/bulkrax/sample_csv_service/mapping_manager.rb', line 6 def mappings @mappings end |
Instance Method Details
#find_by_flag(field_name, default) ⇒ Object
20 21 22 |
# File 'app/services/bulkrax/sample_csv_service/mapping_manager.rb', line 20 def find_by_flag(field_name, default) @mappings.find { |_k, v| v[field_name] == true }&.first || default end |
#key_to_mapped_column(key) ⇒ Object
16 17 18 |
# File 'app/services/bulkrax/sample_csv_service/mapping_manager.rb', line 16 def key_to_mapped_column(key) @mappings.dig(key, "from")&.first || key end |
#mapped_to_key(column_str) ⇒ Object
12 13 14 |
# File 'app/services/bulkrax/sample_csv_service/mapping_manager.rb', line 12 def mapped_to_key(column_str) @mappings.find { |_k, v| v["from"].include?(column_str) }&.first || column_str end |
#split_value_for(mapping_key) ⇒ Object
24 25 26 |
# File 'app/services/bulkrax/sample_csv_service/mapping_manager.rb', line 24 def split_value_for(mapping_key) @mappings.dig(mapping_key, "split") end |