Class: Uniword::Footnote

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

Overview

Represents a footnote in a document.

Responsibility: Store footnote content and metadata. Footnotes appear at the bottom of the page where they are referenced.

A footnote consists of:

  • An ID that uniquely identifies it

  • Content (array of paragraphs)

Examples:

Create a footnote

footnote = Uniword::Footnote.new(
  id: 1,
  content: [paragraph1, paragraph2]
)

Access footnote properties

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Initialize a new Footnote.

Examples:

Create a footnote

footnote = Footnote.new(id: 1, content: [paragraph])

Parameters:

  • id (Integer, String)

    The unique identifier

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

    The footnote content paragraphs



36
37
38
39
# File 'lib/uniword/footnote.rb', line 36

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

Instance Attribute Details

#contentArray<Paragraph>

Returns The content paragraphs of the footnote.

Returns:

  • (Array<Paragraph>)

    The content paragraphs of the footnote



27
28
29
# File 'lib/uniword/footnote.rb', line 27

def content
  @content
end

#idInteger, String

Returns The unique identifier for this footnote.

Returns:

  • (Integer, String)

    The unique identifier for this footnote



24
25
26
# File 'lib/uniword/footnote.rb', line 24

def id
  @id
end

Instance Method Details

#content?Boolean

Check if footnote has content.

Returns:

  • (Boolean)

    true if footnote has content



44
45
46
# File 'lib/uniword/footnote.rb', line 44

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

#textString

Get text content of footnote.

Returns:

  • (String)

    The combined text of all paragraphs



51
52
53
# File 'lib/uniword/footnote.rb', line 51

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 footnote



58
59
60
61
62
63
# File 'lib/uniword/footnote.rb', line 58

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