Module: MappingsHelper

Defined in:
app/helpers/mappings_helper.rb

Overview

MappingsHelper

This module provides helper methods for handling mappings in the application. It includes methods to generate attribute collections and provide mapping and delimiter suggestions based on import configurations.

Instance Method Summary collapse

Instance Method Details

#attribute_collectionArray<String>

Returns a collection of attributes that can be used for mapping.

The collection is generated from importable elements, sorted, and includes additional options for an empty string and “Discard”.

Returns:

  • (Array<String>)

    a sorted array of attribute names with additional options.



15
16
17
18
19
20
# File 'app/helpers/mappings_helper.rb', line 15

def attribute_collection
  attrs = Element.importable.map(&:solr_field).sort
  attrs.prepend("")
  attrs.prepend("Discard")
  attrs
end

#delimiter_suggestion(import, header) ⇒ String, false

Provides a delimiter suggestion for a given header based on the import configuration.

Checks if the header is included in the import’s mapping configuration and returns the delimiter if available.

Parameters:

  • import (Object)

    the import object containing mapping configurations.

  • header (String)

    the header for which the delimiter suggestion is needed.

Returns:

  • (String, false)

    the delimiter if available, otherwise false.



46
47
48
49
50
51
52
# File 'app/helpers/mappings_helper.rb', line 46

def delimiter_suggestion(import, header)
  if import.mapping_configuration.include?(header.to_sym)
    import.mapping_configuration[header.to_sym][:delimited]
  else
    false
  end
end

#mapping_suggestion(import, header) ⇒ String, false

Provides a mapping suggestion for a given header based on the import configuration.

Checks if the header is included in the import’s mapping configuration and returns the destination if available.

Parameters:

  • import (Object)

    the import object containing mapping configurations.

  • header (String)

    the header for which the mapping suggestion is needed.

Returns:

  • (String, false)

    the destination mapping if available, otherwise false.



30
31
32
33
34
35
36
# File 'app/helpers/mappings_helper.rb', line 30

def mapping_suggestion(import, header)
  if import.mapping_configuration.include?(header.to_sym)
    import.mapping_configuration[header.to_sym][:destination]
  else
    false
  end
end