Class: Docbook::XrefResolver
- Inherits:
-
Object
- Object
- Docbook::XrefResolver
- Defined in:
- lib/docbook/xref_resolver.rb
Overview
Resolves xrefs in a DocBook document by building an O(1) xml:id lookup hash and resolving all xref/linkend references to their target titles. Resolves xrefs in a DocBook document by building an O(1) xml:id lookup hash and resolving all xref/linkend references to their target titles.
Instance Method Summary collapse
-
#[](xml_id) ⇒ Docbook::Elements::*?
Get element by xml:id.
-
#initialize(document) ⇒ XrefResolver
constructor
A new instance of XrefResolver.
-
#resolve! ⇒ self
Build the xml:id to element lookup hash.
-
#title_for(linkend) ⇒ String?
Get the resolved title text for a linkend ID.
Constructor Details
#initialize(document) ⇒ XrefResolver
Returns a new instance of XrefResolver.
15 16 17 18 |
# File 'lib/docbook/xref_resolver.rb', line 15 def initialize(document) @document = document @xml_id_map = {} end |
Instance Method Details
#[](xml_id) ⇒ Docbook::Elements::*?
Get element by xml:id.
40 41 42 |
# File 'lib/docbook/xref_resolver.rb', line 40 def [](xml_id) @xml_id_map[xml_id.to_s] end |
#resolve! ⇒ self
Build the xml:id to element lookup hash.
22 23 24 25 |
# File 'lib/docbook/xref_resolver.rb', line 22 def resolve! @xml_id_map = build_xml_id_map(@document) self end |
#title_for(linkend) ⇒ String?
Get the resolved title text for a linkend ID.
30 31 32 33 34 35 |
# File 'lib/docbook/xref_resolver.rb', line 30 def title_for(linkend) target = @xml_id_map[linkend.to_s] return nil unless target best_title(target) end |