Class: Bulkrax::CsvTemplate::MappingManager
- Inherits:
-
Object
- Object
- Bulkrax::CsvTemplate::MappingManager
- Defined in:
- app/services/bulkrax/csv_template/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
- #resolve_column_name(key: nil, flag: nil, default: nil) ⇒ Object
- #split_value_for(mapping_key) ⇒ Object
Constructor Details
#initialize ⇒ MappingManager
Returns a new instance of MappingManager.
9 10 11 |
# File 'app/services/bulkrax/csv_template/mapping_manager.rb', line 9 def initialize @mappings = load_mappings end |
Instance Attribute Details
#mappings ⇒ Object (readonly)
Returns the value of attribute mappings.
7 8 9 |
# File 'app/services/bulkrax/csv_template/mapping_manager.rb', line 7 def mappings @mappings end |
Instance Method Details
#find_by_flag(field_name, default) ⇒ Object
21 22 23 |
# File 'app/services/bulkrax/csv_template/mapping_manager.rb', line 21 def find_by_flag(field_name, default) @mappings.find { |_k, v| v[field_name] == true }&.first || default end |
#key_to_mapped_column(key) ⇒ Object
17 18 19 |
# File 'app/services/bulkrax/csv_template/mapping_manager.rb', line 17 def key_to_mapped_column(key) @mappings.dig(key, "from")&.first || key end |
#mapped_to_key(column_str) ⇒ Object
13 14 15 |
# File 'app/services/bulkrax/csv_template/mapping_manager.rb', line 13 def mapped_to_key(column_str) @mappings.find { |_k, v| v["from"].include?(column_str) }&.first || column_str end |
#resolve_column_name(key: nil, flag: nil, default: nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/bulkrax/csv_template/mapping_manager.rb', line 29 def resolve_column_name(key: nil, flag: nil, default: nil) if flag mapped_key = find_by_flag(flag, nil) if mapped_key = @mappings.dig(mapped_key, "from") || [] return if .any? end end if key = @mappings.dig(key, "from") || [] return if .any? end default ? [default] : [] end |
#split_value_for(mapping_key) ⇒ Object
25 26 27 |
# File 'app/services/bulkrax/csv_template/mapping_manager.rb', line 25 def split_value_for(mapping_key) @mappings.dig(mapping_key, "split") end |