Class: Coradoc::Reference::Catalog::Local

Inherits:
Object
  • Object
show all
Includes:
Protocol
Defined in:
lib/coradoc/reference/catalog/local.rb

Overview

Indexes one CoreModel document. Walks the tree once at construction; indexes every node carrying an id by its anchor Address, plus the document itself by an optional path Address.

catalog = Catalog::Local.from_doc(doc, path: "ELF-5005-1")
catalog.lookup(Address.parse("ELF-5005-1"))        # => doc
catalog.lookup(Address.parse("sec-3"))             # => section

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document:, document_path: nil, index: nil) ⇒ Local

Returns a new instance of Local.



18
19
20
21
22
23
# File 'lib/coradoc/reference/catalog/local.rb', line 18

def initialize(document:, document_path: nil, index: nil)
  @document = document
  @document_path = document_path
  @index = index || MemoryIndex.new
  populate! unless index
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



16
17
18
# File 'lib/coradoc/reference/catalog/local.rb', line 16

def document
  @document
end

#document_pathObject (readonly)

Returns the value of attribute document_path.



16
17
18
# File 'lib/coradoc/reference/catalog/local.rb', line 16

def document_path
  @document_path
end

Class Method Details

.from_doc(document, path: nil) ⇒ Object



26
27
28
# File 'lib/coradoc/reference/catalog/local.rb', line 26

def from_doc(document, path: nil)
  new(document: document, document_path: path)
end

Instance Method Details

#ambiguous?(address) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/coradoc/reference/catalog/local.rb', line 35

def ambiguous?(address)
  @index.ambiguous?(address)
end

#each_pairObject



39
40
41
# File 'lib/coradoc/reference/catalog/local.rb', line 39

def each_pair(&)
  @index.each_pair(&)
end

#lookup(address) ⇒ Object



31
32
33
# File 'lib/coradoc/reference/catalog/local.rb', line 31

def lookup(address)
  @index.lookup(address)
end

#recognizes_scheme?(scheme) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/coradoc/reference/catalog/local.rb', line 43

def recognizes_scheme?(scheme)
  return true if scheme.to_sym == :anchor
  return true if scheme.to_sym == :path && document_path
  return true if scheme.to_sym == :scoped_path && document_path&.include?(':')

  @index.recognizes_scheme?(scheme)
end