Class: Arrolio::Content::Paragraph

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inline_runs = [], style_id: :body, id: nil, footnote_refs: []) ⇒ Paragraph

Returns a new instance of Paragraph.



8
9
10
11
12
13
14
# File 'lib/arrolio/content/paragraph.rb', line 8

def initialize(inline_runs = [], style_id: :body, id: nil, footnote_refs: [])
  @inline_runs = Array(inline_runs).freeze
  @style_id = style_id.to_sym
  @id = id
  @footnote_refs = Array(footnote_refs).freeze
  freeze
end

Instance Attribute Details

#footnote_refsObject (readonly)

Returns the value of attribute footnote_refs.



6
7
8
# File 'lib/arrolio/content/paragraph.rb', line 6

def footnote_refs
  @footnote_refs
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/arrolio/content/paragraph.rb', line 6

def id
  @id
end

#inline_runsObject (readonly)

Returns the value of attribute inline_runs.



6
7
8
# File 'lib/arrolio/content/paragraph.rb', line 6

def inline_runs
  @inline_runs
end

#style_idObject (readonly)

Returns the value of attribute style_id.



6
7
8
# File 'lib/arrolio/content/paragraph.rb', line 6

def style_id
  @style_id
end

Instance Method Details

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



24
25
26
27
28
29
30
# File 'lib/arrolio/content/paragraph.rb', line 24

def ==(other)
  other.is_a?(self.class) &&
    inline_runs == other.inline_runs &&
    style_id == other.style_id &&
    id == other.id &&
    footnote_refs == other.footnote_refs
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @inline_runs.empty? || text.strip.empty?
end

#hashObject



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

def hash
  [self.class, inline_runs, style_id, id, footnote_refs].hash
end

#textObject



16
17
18
# File 'lib/arrolio/content/paragraph.rb', line 16

def text
  @inline_runs.map(&:text).join
end