Class: VRT::Mapping
- Inherits:
-
Object
- Object
- VRT::Mapping
- Defined in:
- lib/vrt/mapping.rb
Instance Method Summary collapse
-
#get(id_list, version) ⇒ Object
returns the most specific value provided in the mapping file for the given vrt id.
-
#initialize(scheme) ⇒ Mapping
constructor
A new instance of Mapping.
Constructor Details
#initialize(scheme) ⇒ Mapping
Returns a new instance of Mapping.
3 4 5 6 |
# File 'lib/vrt/mapping.rb', line 3 def initialize(scheme) @scheme = scheme.to_s load_mappings end |
Instance Method Details
#get(id_list, version) ⇒ Object
returns the most specific value provided in the mapping file for the given vrt id
if no mapping file exists for the given version, the mapping file for the earliest version available will be used
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vrt/mapping.rb', line 11 def get(id_list, version) # update the vrt id to the first version we have a mapping file for unless @mappings.key?(version) id_list = VRT.find_node(vrt_id: id_list.join('.'), preferred_version: @min_version).id_list version = @min_version end # iterate through the id components, keeping track of where we are in the mapping file # and the most specific mapped value found so far mapping = @mappings[version]['content'] best_guess = @mappings[version]['metadata']['default'] id_list.each do |id| entry = mapping[id] break unless entry # mapping file doesn't go this deep, return previous value best_guess = entry[@scheme] if entry[@scheme] # use the children mapping for the next iteration mapping = entry['children'] || {} end best_guess end |