Class: Metanorma::Html::Component::IndexTermCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/html/component/index_term_collector.rb

Instance Method Summary collapse

Constructor Details

#initializeIndexTermCollector

Returns a new instance of IndexTermCollector.



7
8
9
# File 'lib/metanorma/html/component/index_term_collector.rb', line 7

def initialize
  @terms = []
end

Instance Method Details

#add(primary:, secondary: nil, tertiary: nil, see: nil, see_also: nil, target_id: nil, target_text: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/metanorma/html/component/index_term_collector.rb', line 11

def add(primary:, secondary: nil, tertiary: nil,
        see: nil, see_also: nil, target_id: nil, target_text: nil)
  @terms << IndexTerm.new(
    primary: primary,
    secondary: secondary,
    tertiary: tertiary,
    see: see,
    see_also: see_also,
    target_id: target_id,
    target_text: target_text
  )
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/metanorma/html/component/index_term_collector.rb', line 24

def empty?
  @terms.empty?
end

#sorted_groupsObject



28
29
30
31
32
33
34
35
36
# File 'lib/metanorma/html/component/index_term_collector.rb', line 28

def sorted_groups
  grouped = @terms
    .group_by { |t| t.primary[0].upcase }
    .sort_by { |letter, _| letter }

  grouped.map do |letter, terms|
    IndexLetterGroup.new(letter: letter, entries: merge_entries(terms))
  end
end