Class: Metanorma::Html::Component::IndexEntry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndexEntry

Returns a new instance of IndexEntry.



71
72
73
74
75
76
# File 'lib/metanorma/html/component/index_term_collector.rb', line 71

def initialize(*)
  super
  self.locators ||= []
  self.see_also_entries ||= []
  self.children ||= []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children

Returns:

  • (Object)

    the current value of children



69
70
71
# File 'lib/metanorma/html/component/index_term_collector.rb', line 69

def children
  @children
end

#locatorsObject

Returns the value of attribute locators

Returns:

  • (Object)

    the current value of locators



69
70
71
# File 'lib/metanorma/html/component/index_term_collector.rb', line 69

def locators
  @locators
end

#seeObject

Returns the value of attribute see

Returns:

  • (Object)

    the current value of see



69
70
71
# File 'lib/metanorma/html/component/index_term_collector.rb', line 69

def see
  @see
end

#see_also_entriesObject

Returns the value of attribute see_also_entries

Returns:

  • (Object)

    the current value of see_also_entries



69
70
71
# File 'lib/metanorma/html/component/index_term_collector.rb', line 69

def see_also_entries
  @see_also_entries
end

#termObject

Returns the value of attribute term

Returns:

  • (Object)

    the current value of term



69
70
71
# File 'lib/metanorma/html/component/index_term_collector.rb', line 69

def term
  @term
end

Instance Method Details

#add_locator(id, text) ⇒ Object



78
79
80
# File 'lib/metanorma/html/component/index_term_collector.rb', line 78

def add_locator(id, text)
  locators << IndexLocator.new(id: id, text: text) if id && !locators.any? { |l| l.id == id }
end

#add_see_also(term) ⇒ Object



82
83
84
# File 'lib/metanorma/html/component/index_term_collector.rb', line 82

def add_see_also(term)
  see_also_entries << term if term
end

#find_or_add_child(term_name) ⇒ Object



86
87
88
89
90
91
92
93
# File 'lib/metanorma/html/component/index_term_collector.rb', line 86

def find_or_add_child(term_name)
  existing = children.find { |c| c.term.downcase == term_name.downcase }
  existing || begin
    child = IndexEntry.new(term: term_name)
    children << child
    child
  end
end