Class: Metanorma::Html::Component::FootnoteCollector
- Inherits:
-
Object
- Object
- Metanorma::Html::Component::FootnoteCollector
- Defined in:
- lib/metanorma/html/component/footnote_collector.rb
Overview
Collects footnote content encountered during rendering. Deduplicates by reference letter/number so each footnote definition appears once, even when referenced from multiple locations.
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize ⇒ FootnoteCollector
constructor
A new instance of FootnoteCollector.
-
#register(fn) ⇒ Object
Register a footnote and return its sequential number.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ FootnoteCollector
Returns a new instance of FootnoteCollector.
10 11 12 13 14 |
# File 'lib/metanorma/html/component/footnote_collector.rb', line 10 def initialize @footnotes = [] @ref_map = {} @id_map = {} end |
Instance Method Details
#each(&blk) ⇒ Object
44 45 46 |
# File 'lib/metanorma/html/component/footnote_collector.rb', line 44 def each(&blk) @footnotes.each(&blk) end |
#empty? ⇒ Boolean
40 41 42 |
# File 'lib/metanorma/html/component/footnote_collector.rb', line 40 def empty? @footnotes.empty? end |
#register(fn) ⇒ Object
Register a footnote and return its sequential number. Deduplicates by reference: same reference = same footnote number.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/metanorma/html/component/footnote_collector.rb', line 18 def register(fn) fn_id = fn.id || fn.reference.to_s ref = fn.reference.to_s # If we've seen this reference before, reuse its number if @ref_map.key?(ref) return @ref_map[ref] end number = @footnotes.size + 1 @ref_map[ref] = number @id_map[fn_id] = number @footnotes << FootnoteEntry.new( id: fn_id, number: number, reference: ref, content: fn.p, fmt_label: fn.fmt_fn_label ) number end |
#to_a ⇒ Object
48 49 50 |
# File 'lib/metanorma/html/component/footnote_collector.rb', line 48 def to_a @footnotes end |