Class: EBPS::Text::Chapter
- Inherits:
-
Object
- Object
- EBPS::Text::Chapter
- Defined in:
- lib/ebps/text/chapter.rb
Instance Attribute Summary collapse
-
#heading ⇒ Object
readonly
Returns the value of attribute heading.
-
#paragraphs ⇒ Object
readonly
Returns the value of attribute paragraphs.
Instance Method Summary collapse
- #add_paragraph(paragraph) ⇒ Object
- #append(chapter) ⇒ Object
-
#initialize ⇒ Chapter
constructor
A new instance of Chapter.
- #partial? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Chapter
Returns a new instance of Chapter.
9 10 11 12 |
# File 'lib/ebps/text/chapter.rb', line 9 def initialize @heading = '' @paragraphs = [] end |
Instance Attribute Details
#heading ⇒ Object (readonly)
Returns the value of attribute heading.
8 9 10 |
# File 'lib/ebps/text/chapter.rb', line 8 def heading @heading end |
#paragraphs ⇒ Object (readonly)
Returns the value of attribute paragraphs.
8 9 10 |
# File 'lib/ebps/text/chapter.rb', line 8 def paragraphs @paragraphs end |
Instance Method Details
#add_paragraph(paragraph) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ebps/text/chapter.rb', line 13 def add_paragraph(paragraph) case paragraph when Paragraph, Picture, Table else raise TypeError end unless @paragraphs.include?(paragraph) @paragraphs.push paragraph paragraph end end |
#append(chapter) ⇒ Object
24 25 26 |
# File 'lib/ebps/text/chapter.rb', line 24 def append chapter @paragraphs.concat chapter.paragraphs end |
#partial? ⇒ Boolean
27 28 29 |
# File 'lib/ebps/text/chapter.rb', line 27 def partial? @heading.empty? || @paragraphs.empty? end |
#to_s ⇒ Object
30 31 32 33 |
# File 'lib/ebps/text/chapter.rb', line 30 def to_s head = @heading.empty? ? [] : [@heading] head.concat(@paragraphs).join("\n") end |