Class: EBPS::Text::Document

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



8
9
10
11
12
# File 'lib/ebps/text/document.rb', line 8

def initialize
  @chapters = []
  @metadata = {}
  @title = ''
end

Instance Attribute Details

#chaptersObject (readonly)

Returns the value of attribute chapters.



6
7
8
# File 'lib/ebps/text/document.rb', line 6

def chapters
  @chapters
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/ebps/text/document.rb', line 6

def 
  @metadata
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/ebps/text/document.rb', line 7

def title
  @title
end

Instance Method Details

#add_chapter(chapter) ⇒ Object

Raises:

  • (TypeError)


13
14
15
16
17
18
19
# File 'lib/ebps/text/document.rb', line 13

def add_chapter(chapter)
  raise TypeError unless chapter.is_a?(Chapter)
  unless @chapters.include?(chapter)
    @chapters.push chapter
    chapter
  end
end

#chapter(idx_or_name) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/ebps/text/document.rb', line 20

def chapter(idx_or_name)
  case idx_or_name
  when Integer
    @chapters[idx_or_name]
  else
    @chapters.find { |ch| ch.name == idx_or_name }
  end
end

#remove_chapter(chapter) ⇒ Object



28
29
30
# File 'lib/ebps/text/document.rb', line 28

def remove_chapter(chapter)
  @chapters.delete(chapter)
end

#to_sObject



31
32
33
# File 'lib/ebps/text/document.rb', line 31

def to_s
  @chapters.join("\n")
end