Class: Glossarist::ResolutionAdapter::Route

Inherits:
Glossarist::ResolutionAdapter show all
Defined in:
lib/glossarist/resolution_adapter/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routes = {}) ⇒ Route

Returns a new instance of Route.



8
9
10
11
# File 'lib/glossarist/resolution_adapter/route.rb', line 8

def initialize(routes = {})
  super()
  @routes = routes
end

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



6
7
8
# File 'lib/glossarist/resolution_adapter/route.rb', line 6

def routes
  @routes
end

Instance Method Details

#add(from:, to:) ⇒ Object



13
14
15
# File 'lib/glossarist/resolution_adapter/route.rb', line 13

def add(from:, to:)
  @routes[from] = to
end

#remap(source) ⇒ Object



29
30
31
# File 'lib/glossarist/resolution_adapter/route.rb', line 29

def remap(source)
  routes[source] || source
end

#resolve(reference) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/glossarist/resolution_adapter/route.rb', line 17

def resolve(reference)
  return nil unless reference.ref_type == "urn"
  return nil unless routes.key?(reference.source)

  ConceptReference.new(
    term: reference.term,
    concept_id: reference.concept_id,
    source: routes[reference.source],
    ref_type: reference.ref_type,
  )
end