Class: Arrolio::Content::Heading

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

Overview

A semantic heading. Distinct from Paragraph so the renderer can emit PDF structure tags (for accessibility/ToC), the engine can record heading → page mappings for cross-references, and the FlowBuilder can apply distinct rendering rules (keep_together, page-break-before, outline level).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level:, title:, number: nil, id: nil, style_id: :heading_1) ⇒ Heading

Returns a new instance of Heading.



13
14
15
16
17
18
19
20
# File 'lib/arrolio/content/heading.rb', line 13

def initialize(level:, title:, number: nil, id: nil, style_id: :heading_1)
  @level = level.to_i
  @number = number&.to_s
  @title = title.to_s
  @id = id&.to_s
  @style_id = style_id.to_sym
  freeze
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/arrolio/content/heading.rb', line 11

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



11
12
13
# File 'lib/arrolio/content/heading.rb', line 11

def level
  @level
end

#numberObject (readonly)

Returns the value of attribute number.



11
12
13
# File 'lib/arrolio/content/heading.rb', line 11

def number
  @number
end

#style_idObject (readonly)

Returns the value of attribute style_id.



11
12
13
# File 'lib/arrolio/content/heading.rb', line 11

def style_id
  @style_id
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/arrolio/content/heading.rb', line 11

def title
  @title
end

Instance Method Details

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



22
23
24
25
26
27
28
29
# File 'lib/arrolio/content/heading.rb', line 22

def ==(other)
  other.is_a?(self.class) &&
    level == other.level &&
    number == other.number &&
    title == other.title &&
    id == other.id &&
    style_id == other.style_id
end

#hashObject



33
34
35
# File 'lib/arrolio/content/heading.rb', line 33

def hash
  [self.class, level, number, title, id, style_id].hash
end

#inline_header?Boolean

Returns:

  • (Boolean)


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

def inline_header?
  !number.nil? && title.empty?
end