Class: EBPS::Text::Document
- Inherits:
-
Object
- Object
- EBPS::Text::Document
- Defined in:
- lib/ebps/text/document.rb
Instance Attribute Summary collapse
-
#chapters ⇒ Object
readonly
Returns the value of attribute chapters.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #add_chapter(chapter) ⇒ Object
- #chapter(idx_or_name) ⇒ Object
-
#initialize ⇒ Document
constructor
A new instance of Document.
- #remove_chapter(chapter) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Document
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
#chapters ⇒ Object (readonly)
Returns the value of attribute chapters.
6 7 8 |
# File 'lib/ebps/text/document.rb', line 6 def chapters @chapters end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/ebps/text/document.rb', line 6 def @metadata end |
#title ⇒ Object
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
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_s ⇒ Object
31 32 33 |
# File 'lib/ebps/text/document.rb', line 31 def to_s @chapters.join("\n") end |