Class: Arrolio::Content::IndexEntry
- Inherits:
-
Object
- Object
- Arrolio::Content::IndexEntry
- Defined in:
- lib/arrolio/content/index_entry.rb
Overview
A single index entry — a term and the page(s) where it appears.
Part of a back-of-book index section. The adapter extracts
these from
Instance Attribute Summary collapse
-
#page_numbers ⇒ Object
readonly
Returns the value of attribute page_numbers.
-
#see_also ⇒ Object
readonly
Returns the value of attribute see_also.
-
#style_id ⇒ Object
readonly
Returns the value of attribute style_id.
-
#term ⇒ Object
readonly
Returns the value of attribute term.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #add_page(number) ⇒ Object
- #first_letter ⇒ Object
- #hash ⇒ Object
-
#initialize(term:, page_numbers:, see_also: [], style_id: :index_entry) ⇒ IndexEntry
constructor
A new instance of IndexEntry.
- #page_numbers_str ⇒ Object
Constructor Details
#initialize(term:, page_numbers:, see_also: [], style_id: :index_entry) ⇒ IndexEntry
Returns a new instance of IndexEntry.
12 13 14 15 16 17 18 |
# File 'lib/arrolio/content/index_entry.rb', line 12 def initialize(term:, page_numbers:, see_also: [], style_id: :index_entry) @term = term.to_s @page_numbers = Array(page_numbers).map(&:to_i).sort.uniq.freeze @see_also = Array(see_also).map(&:to_s).freeze @style_id = style_id.to_sym freeze end |
Instance Attribute Details
#page_numbers ⇒ Object (readonly)
Returns the value of attribute page_numbers.
10 11 12 |
# File 'lib/arrolio/content/index_entry.rb', line 10 def page_numbers @page_numbers end |
#see_also ⇒ Object (readonly)
Returns the value of attribute see_also.
10 11 12 |
# File 'lib/arrolio/content/index_entry.rb', line 10 def see_also @see_also end |
#style_id ⇒ Object (readonly)
Returns the value of attribute style_id.
10 11 12 |
# File 'lib/arrolio/content/index_entry.rb', line 10 def style_id @style_id end |
#term ⇒ Object (readonly)
Returns the value of attribute term.
10 11 12 |
# File 'lib/arrolio/content/index_entry.rb', line 10 def term @term end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
39 40 41 42 43 44 |
# File 'lib/arrolio/content/index_entry.rb', line 39 def ==(other) other.is_a?(self.class) && term == other.term && page_numbers == other.page_numbers && see_also == other.see_also end |
#add_page(number) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/arrolio/content/index_entry.rb', line 20 def add_page(number) return self if @page_numbers.include?(number.to_i) self.class.new( term: @term, page_numbers: @page_numbers + [number.to_i], see_also: @see_also, style_id: @style_id ) end |
#first_letter ⇒ Object
31 32 33 |
# File 'lib/arrolio/content/index_entry.rb', line 31 def first_letter @term[0]&.upcase || '' end |
#hash ⇒ Object
47 48 49 |
# File 'lib/arrolio/content/index_entry.rb', line 47 def hash [self.class, term, page_numbers, see_also].hash end |
#page_numbers_str ⇒ Object
35 36 37 |
# File 'lib/arrolio/content/index_entry.rb', line 35 def page_numbers_str @page_numbers.join(', ') end |