Class: Glossarist::ResolutionAdapter::Local

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(concepts) ⇒ Local

Returns a new instance of Local.



8
9
10
11
12
13
# File 'lib/glossarist/resolution_adapter/local.rb', line 8

def initialize(concepts)
  super()
  @concepts = concepts
  @index = {}
  build_index
end

Instance Attribute Details

#conceptsObject (readonly)

Returns the value of attribute concepts.



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

def concepts
  @concepts
end

#indexObject (readonly)

Returns the value of attribute index.



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

def index
  @index
end

Instance Method Details

#resolve(reference) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/glossarist/resolution_adapter/local.rb', line 15

def resolve(reference)
  case reference.ref_type
  when "local"
    resolve_by_id(reference.concept_id)
  when "designation"
    resolve_by_designation(reference.term)
  else
    resolve_by_id(reference.concept_id) if reference.concept_id
  end
end

#resolve_by_designation(term) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/glossarist/resolution_adapter/local.rb', line 30

def resolve_by_designation(term)
  return nil unless term

  downcased = term.downcase
  concepts.find do |concept|
    designations_for(concept).any? { |d| d&.downcase == downcased }
  end
end

#resolve_by_id(concept_id) ⇒ Object



26
27
28
# File 'lib/glossarist/resolution_adapter/local.rb', line 26

def resolve_by_id(concept_id)
  @index[concept_id]
end