Class: Arrolio::Content::BibliographyItem

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/content/bibliography_item.rb

Overview

A single bibliography entry: citation tag (e.g. "[Smith2020]") and a formatted reference Paragraph. Renders with a hanging-indent so wrapped lines align under the text, not the citation tag.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(formattedref:, tag: nil, id: nil, style_id: :bibitem) ⇒ BibliographyItem

Returns a new instance of BibliographyItem.



12
13
14
15
16
17
18
# File 'lib/arrolio/content/bibliography_item.rb', line 12

def initialize(formattedref:, tag: nil, id: nil, style_id: :bibitem)
  @tag = tag
  @formattedref = formattedref
  @id = id&.to_s
  @style_id = style_id.to_sym
  freeze
end

Instance Attribute Details

#formattedrefObject (readonly)

Returns the value of attribute formattedref.



10
11
12
# File 'lib/arrolio/content/bibliography_item.rb', line 10

def formattedref
  @formattedref
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/arrolio/content/bibliography_item.rb', line 10

def id
  @id
end

#style_idObject (readonly)

Returns the value of attribute style_id.



10
11
12
# File 'lib/arrolio/content/bibliography_item.rb', line 10

def style_id
  @style_id
end

#tagObject (readonly)

Returns the value of attribute tag.



10
11
12
# File 'lib/arrolio/content/bibliography_item.rb', line 10

def tag
  @tag
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



28
29
30
31
32
33
34
# File 'lib/arrolio/content/bibliography_item.rb', line 28

def ==(other)
  other.is_a?(self.class) &&
    tag == other.tag &&
    formattedref == other.formattedref &&
    id == other.id &&
    style_id == other.style_id
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/arrolio/content/bibliography_item.rb', line 24

def empty?
  @tag.nil? && (@formattedref.nil? || (@formattedref.is_a?(Paragraph) && @formattedref.empty?))
end

#hashObject



37
38
39
# File 'lib/arrolio/content/bibliography_item.rb', line 37

def hash
  [self.class, tag, formattedref, id, style_id].hash
end

#textObject



20
21
22
# File 'lib/arrolio/content/bibliography_item.rb', line 20

def text
  @formattedref.is_a?(Paragraph) ? @formattedref.text : @formattedref.to_s
end