Class: Rpub::Book
- Inherits:
-
Object
- Object
- Rpub::Book
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/rpub/book.rb
Overview
The Book object wraps a collection of chapter objects and knows about its ordering, the book metadata from the configuration file and the book output filename.
Instance Attribute Summary (collapse)
-
- (Array<Chapter>) chapters
readonly
List of chapters, one for every input markdown file.
Instance Method Summary (collapse)
-
- (Object) add_chapter(content)
(also: #<<)
Add textual content as a new Chapter to this book.
-
- (Object) each(&block)
-
- (String) filename
Output filename for epub, based on the book title and version number.
-
- (Boolean) has_cover?
-
- (Boolean) has_fonts?
-
- (Boolean) has_toc?
-
- (Object) images
-
- (Book) initialize(context)
constructor
A new instance of Book.
-
- (Object) outline
-
- (String) uid
Unique identifier for this entire book to be used in the epub manifest files.
Constructor Details
- (Book) initialize(context)
A new instance of Book
14 15 16 17 18 |
# File 'lib/rpub/book.rb', line 14 def initialize(context) @chapters = [] @context = context @context.chapter_files.each(&method(:<<)) end |
Instance Attribute Details
- (Array<Chapter>) chapters (readonly)
List of chapters, one for every input markdown file.
12 13 14 |
# File 'lib/rpub/book.rb', line 12 def chapters @chapters end |
Instance Method Details
- (Object) add_chapter(content) Also known as: <<
Add textual content as a new Chapter to this book.
This method returns the Book
object iself, so you can chain multiple calls:
52 53 54 55 |
# File 'lib/rpub/book.rb', line 52 def add_chapter(content) chapters << Chapter.new(content, chapters.size, layout) self end |
- (Object) each(&block)
20 21 22 |
# File 'lib/rpub/book.rb', line 20 def each(&block) chapters.each(&block) end |
- (String) filename
Output filename for epub, based on the book title and version number.
66 67 68 |
# File 'lib/rpub/book.rb', line 66 def filename @filename ||= [config.title, config.version].join('-').gsub(/[^\w\.]/i, '-').squeeze('-').downcase.chomp('-') + '.epub' end |
- (Boolean) has_cover?
32 33 34 |
# File 'lib/rpub/book.rb', line 32 def has_cover? !!config.cover_image end |
- (Boolean) has_fonts?
24 25 26 |
# File 'lib/rpub/book.rb', line 24 def has_fonts? fonts.any? end |
- (Boolean) has_toc?
28 29 30 |
# File 'lib/rpub/book.rb', line 28 def has_toc? !!config.toc end |
- (Object) images
40 41 42 |
# File 'lib/rpub/book.rb', line 40 def images map { |chapter| chapter.images }.flatten.uniq end |
- (Object) outline
36 37 38 |
# File 'lib/rpub/book.rb', line 36 def outline inject([]) { |all, chapter| all << [chapter.filename, chapter.outline] } end |
- (String) uid
Unique identifier for this entire book to be used in the epub manifest files.
60 61 62 |
# File 'lib/rpub/book.rb', line 60 def uid @uid ||= Digest::SHA1.hexdigest [config.inspect, map(&:uid)].join end |