Class: Coradoc::Reference::Catalog::Local
- Inherits:
-
Object
- Object
- Coradoc::Reference::Catalog::Local
- 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
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#document_path ⇒ Object
readonly
Returns the value of attribute document_path.
Class Method Summary collapse
Instance Method Summary collapse
- #ambiguous?(address) ⇒ Boolean
- #each_pair ⇒ Object
-
#initialize(document:, document_path: nil, index: nil) ⇒ Local
constructor
A new instance of Local.
- #lookup(address) ⇒ Object
- #recognizes_scheme?(scheme) ⇒ Boolean
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
#document ⇒ Object (readonly)
Returns the value of attribute document.
16 17 18 |
# File 'lib/coradoc/reference/catalog/local.rb', line 16 def document @document end |
#document_path ⇒ Object (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
35 36 37 |
# File 'lib/coradoc/reference/catalog/local.rb', line 35 def ambiguous?(address) @index.ambiguous?(address) end |
#each_pair ⇒ Object
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
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 |