Class: Rpub::Chapter
- Inherits:
-
Object
- Object
- Rpub::Chapter
- Extended by:
- Forwardable
- Defined in:
- lib/rpub/chapter.rb
Overview
Representation of a chapter in the book, from a single input file from the project directory. The Chapter object knows how to turn itself into HTML suitable for writing to the epub archive with the appropriate identifiers to be listed in the epub manifest files.
Instance Attribute Summary collapse
-
#content ⇒ String
readonly
Raw textual contents of this chapter.
-
#layout ⇒ String
readonly
Filename of the layout to use, to be passed directly to the Kramdown gem.
-
#number ⇒ Fixnum
readonly
Chapter number provided by its associated Book object.
Instance Method Summary collapse
-
#filename ⇒ String
Name for the file in the zip to use, based on the title.
-
#initialize(content, number, layout) ⇒ Chapter
constructor
A new instance of Chapter.
-
#uid ⇒ String
Unique identifier for this chapter.
-
#xml_id ⇒ String
XML-friendly slug for this chapter based on its number.
Constructor Details
#initialize(content, number, layout) ⇒ Chapter
Returns a new instance of Chapter.
19 20 21 22 |
# File 'lib/rpub/chapter.rb', line 19 def initialize(content, number, layout) @content, @number, @layout = content, number, layout @document = Rpub.document_factory.call(content, layout) end |
Instance Attribute Details
#content ⇒ String (readonly)
Returns raw textual contents of this chapter.
11 12 13 |
# File 'lib/rpub/chapter.rb', line 11 def content @content end |
#layout ⇒ String (readonly)
Returns filename of the layout to use, to be passed directly to the Kramdown gem.
17 18 19 |
# File 'lib/rpub/chapter.rb', line 17 def layout @layout end |
#number ⇒ Fixnum (readonly)
Returns chapter number provided by its associated Book object.
14 15 16 |
# File 'lib/rpub/chapter.rb', line 14 def number @number end |
Instance Method Details
#filename ⇒ String
Returns name for the file in the zip to use, based on the title.
35 36 37 |
# File 'lib/rpub/chapter.rb', line 35 def filename @filename ||= xml_id.to_s + '-' + title.gsub(/[^\w\.]/i, '-').squeeze('-').downcase.chomp('-') + '.html' end |
#uid ⇒ String
Returns Unique identifier for this chapter.
25 26 27 |
# File 'lib/rpub/chapter.rb', line 25 def uid @uid ||= Digest::SHA1.hexdigest([content, xml_id.to_s, layout].join) end |
#xml_id ⇒ String
Returns XML-friendly slug for this chapter based on its number.
30 31 32 |
# File 'lib/rpub/chapter.rb', line 30 def xml_id @id ||= "chapter-#{number}" end |