Class: Bookie::Book

Inherits:
Object
  • Object
show all
Defined in:
lib/bookie/book.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#chaptersObject (readonly)

Returns the value of attribute chapters.



8
9
10
# File 'lib/bookie/book.rb', line 8

def chapters
  @chapters
end

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