Class: EBPS::Text::Chapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ebps/text/chapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChapter

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

#headingObject (readonly)

Returns the value of attribute heading.



8
9
10
# File 'lib/ebps/text/chapter.rb', line 8

def heading
  @heading
end

#paragraphsObject (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

Returns:

  • (Boolean)


27
28
29
# File 'lib/ebps/text/chapter.rb', line 27

def partial?
  @heading.empty? || @paragraphs.empty?
end

#to_sObject



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