Class: Bookie::Book
- Inherits:
-
Object
- Object
- Bookie::Book
- Defined in:
- lib/bookie/book.rb
Instance Attribute Summary collapse
-
#chapters ⇒ Object
readonly
Returns the value of attribute chapters.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #chapter(name, file) ⇒ Object
-
#initialize(name) ⇒ Book
constructor
A new instance of Book.
-
#render(basename, emitters) ⇒ Object
FIXME: This is inefficient, it should be possible to fire up the parser just once with many emitters.
Constructor Details
#initialize(name) ⇒ Book
Returns a new instance of Book.
3 4 5 6 |
# File 'lib/bookie/book.rb', line 3 def initialize(name) @name = name @chapters = [] end |
Instance Attribute Details
#chapters ⇒ Object (readonly)
Returns the value of attribute chapters.
8 9 10 |
# File 'lib/bookie/book.rb', line 8 def chapters @chapters end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/bookie/book.rb', line 8 def name @name end |
Instance Method Details
#chapter(name, file) ⇒ Object
10 11 12 |
# File 'lib/bookie/book.rb', line 10 def chapter(name, file) chapters << [name, file] end |
#render(basename, emitters) ⇒ Object
FIXME: This is inefficient, it should be possible to fire up the parser just once with many emitters.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/bookie/book.rb', line 16 def render(basename, emitters) emitters.each do |emitter| chapters.each_with_index do |(name, file), i| emitter.start_new_chapter(header: "Chapter #{i+1}", title: name) Bookie::Parser.parse(File.read(file), emitter) end output_file = "#{basename}#{emitter.class.extension}" emitter.render(file: output_file) end end |