Class: Arrolio::Content::Example
- Inherits:
-
Object
- Object
- Arrolio::Content::Example
- 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
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#style_id ⇒ Object
readonly
Returns the value of attribute style_id.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #body_text ⇒ Object
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(body:, label: '', id: nil, style_id: :example) ⇒ Example
constructor
A new instance of Example.
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/arrolio/content/example.rb', line 9 def body @body end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/arrolio/content/example.rb', line 9 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
9 10 11 |
# File 'lib/arrolio/content/example.rb', line 9 def label @label end |
#style_id ⇒ Object (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_text ⇒ Object
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
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 |
#hash ⇒ Object
38 39 40 |
# File 'lib/arrolio/content/example.rb', line 38 def hash [self.class, label, body, id, style_id].hash end |