Class: Uniword::Endnote

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/endnote.rb

Overview

Represents an endnote in a document.

Responsibility: Store endnote content and metadata. Endnotes appear at the end of the document or section, unlike footnotes which appear at the bottom of each page.

An endnote consists of:

  • An ID that uniquely identifies it

  • Content (array of paragraphs)

Examples:

Create an endnote

endnote = Uniword::Endnote.new(
  id: 1,
  content: [paragraph1, paragraph2]
)

Access endnote properties

endnote.id       # => 1
endnote.content  # => [paragraph1, paragraph2]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, content: []) ⇒ Endnote

Initialize a new Endnote.

Examples:

Create an endnote

endnote = Endnote.new(id: 1, content: [paragraph])

Parameters:

  • id (Integer, String)

    The unique identifier

  • content (Array<Paragraph>) (defaults to: [])

    The endnote content paragraphs



37
38
39
40
# File 'lib/uniword/endnote.rb', line 37

def initialize(id:, content: [])
  @id = id
  @content = content
end

Instance Attribute Details

#contentArray<Paragraph>

Returns The content paragraphs of the endnote.

Returns:

  • (Array<Paragraph>)

    The content paragraphs of the endnote



28
29
30
# File 'lib/uniword/endnote.rb', line 28

def content
  @content
end

#idInteger, String

Returns The unique identifier for this endnote.

Returns:

  • (Integer, String)

    The unique identifier for this endnote



25
26
27
# File 'lib/uniword/endnote.rb', line 25

def id
  @id
end

Instance Method Details

#content?Boolean

Check if endnote has content.

Returns:

  • (Boolean)

    true if endnote has content



45
46
47
# File 'lib/uniword/endnote.rb', line 45

def content?
  !@content.nil? && !@content.empty?
end

#textString

Get text content of endnote.

Returns:

  • (String)

    The combined text of all paragraphs



52
53
54
# File 'lib/uniword/endnote.rb', line 52

def text
  @content.map { |p| p.respond_to?(:text) ? p.text : p.to_s }.join("\n")
end

#to_hHash

Convert to hash representation.

Returns:

  • (Hash)

    Hash representation of the endnote



59
60
61
62
63
64
# File 'lib/uniword/endnote.rb', line 59

def to_h
  {
    id: @id,
    content: @content,
  }
end