Class: Arrolio::Content::Example

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

Overview

A semantic example group. Same shape as Note but carries the :example style_id by default so the flow builder can apply the XSL's example-body-style margin-left to the body Paragraphs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body:, label: '', id: nil, style_id: :example) ⇒ Example

Returns a new instance of Example.



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

def initialize(body:, label: '', id: nil, style_id: :example)
  @label = label.to_s
  @body = Array(body).freeze
  @id = id&.to_s
  @style_id = style_id.to_sym
  freeze
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



9
10
11
# File 'lib/arrolio/content/example.rb', line 9

def body
  @body
end

#idObject (readonly)

Returns the value of attribute id.



9
10
11
# File 'lib/arrolio/content/example.rb', line 9

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



9
10
11
# File 'lib/arrolio/content/example.rb', line 9

def label
  @label
end

#style_idObject (readonly)

Returns the value of attribute style_id.



9
10
11
# File 'lib/arrolio/content/example.rb', line 9

def style_id
  @style_id
end

Instance Method Details

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



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

def ==(other)
  other.is_a?(self.class) &&
    label == other.label &&
    body == other.body &&
    id == other.id &&
    style_id == other.style_id
end

#body_textObject



19
20
21
22
23
# File 'lib/arrolio/content/example.rb', line 19

def body_text
  @body.map do |node|
    node.is_a?(Paragraph) ? node.text : node.to_s
  end.join(' ')
end

#empty?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/arrolio/content/example.rb', line 25

def empty?
  @body.empty? || @body.all? { |node| node.is_a?(Paragraph) && node.empty? }
end

#hashObject



38
39
40
# File 'lib/arrolio/content/example.rb', line 38

def hash
  [self.class, label, body, id, style_id].hash
end