Class: Metanorma::Iso::Sts::Transformer::FootnoteCollector
- Inherits:
-
Object
- Object
- Metanorma::Iso::Sts::Transformer::FootnoteCollector
- Defined in:
- lib/metanorma/iso/sts/transformer/footnote_collector.rb
Instance Method Summary collapse
- #count ⇒ Object
- #empty? ⇒ Boolean
- #fn_group ⇒ Object
-
#initialize ⇒ FootnoteCollector
constructor
A new instance of FootnoteCollector.
- #lookup(footnote_text) ⇒ Object
- #register(footnote_text, paragraphs: nil) ⇒ Object
Constructor Details
#initialize ⇒ FootnoteCollector
Returns a new instance of FootnoteCollector.
7 8 9 10 |
# File 'lib/metanorma/iso/sts/transformer/footnote_collector.rb', line 7 def initialize @footnotes = {} @counter = 0 end |
Instance Method Details
#count ⇒ Object
33 34 35 |
# File 'lib/metanorma/iso/sts/transformer/footnote_collector.rb', line 33 def count @footnotes.size end |
#empty? ⇒ Boolean
29 30 31 |
# File 'lib/metanorma/iso/sts/transformer/footnote_collector.rb', line 29 def empty? @footnotes.empty? end |
#fn_group ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/metanorma/iso/sts/transformer/footnote_collector.rb', line 37 def fn_group return nil if @footnotes.empty? group = build_ordered_fn_group @footnotes.each do |text, entry| fn = build_ordered_fn fn.id = entry[:id] fn_label = ::Sts::IsoSts::Label.new fn_label.content = ["<sup>#{entry[:number]})</sup>"] fn.label = fn_label paras = entry[:paragraphs] if paras && !paras.empty? paras.each { |para| fn.paragraph para } else fn_para = ::Sts::IsoSts::Paragraph.new fn_para.content = [text] fn.paragraph fn_para end group.fn fn end group end |
#lookup(footnote_text) ⇒ Object
25 26 27 |
# File 'lib/metanorma/iso/sts/transformer/footnote_collector.rb', line 25 def lookup(footnote_text) @footnotes[footnote_text.strip] end |
#register(footnote_text, paragraphs: nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/metanorma/iso/sts/transformer/footnote_collector.rb', line 12 def register(footnote_text, paragraphs: nil) normalized = footnote_text.strip if @footnotes.key?(normalized) @footnotes[normalized] else @counter += 1 entry = { id: "fn_#{@counter}", number: @counter, paragraphs: paragraphs } @footnotes[normalized] = entry entry end end |