Class: Bindery::BookBuilder
- Inherits:
-
Object
- Object
- Bindery::BookBuilder
show all
- Includes:
- ContentMethods
- Defined in:
- lib/bindery/book_builder.rb
Constant Summary
collapse
- Metadata =
{
:contributor => nil,
:cover => :special,
:coverage => nil,
:creator => nil,
:date => nil,
:description => nil,
:format => nil,
:identifier => :required,
:language => :required,
:publisher => nil,
:relation => nil,
:rights => nil,
:source => nil,
:subject => nil,
:title => :required,
:type => nil
}
Instance Attribute Summary collapse
Instance Method Summary
collapse
#appendix, #chapter, #div, #part, #section
Constructor Details
Returns a new instance of BookBuilder.
27
28
29
|
# File 'lib/bindery/book_builder.rb', line 27
def initialize
self.book = ::Bindery::Book.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/bindery/book_builder.rb', line 66
def method_missing(name, *args, &block)
if Metadata.include?(name.to_sym)
metadata_element(name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#book ⇒ Object
Returns the value of attribute book.
4
5
6
|
# File 'lib/bindery/book_builder.rb', line 4
def book
@book
end
|
Instance Method Details
#author(author) ⇒ Object
96
97
98
|
# File 'lib/bindery/book_builder.rb', line 96
def author(author)
book.author = author
end
|
#divisions ⇒ Object
41
42
43
|
# File 'lib/bindery/book_builder.rb', line 41
def divisions
book.divisions
end
|
31
32
33
34
|
# File 'lib/bindery/book_builder.rb', line 31
def format(fmt)
raise "unsupported format :#{fmt}" unless [:epub].include?(fmt)
book.formats << fmt
end
|
#isbn(isbn) ⇒ Object
80
81
82
|
# File 'lib/bindery/book_builder.rb', line 80
def isbn(isbn)
book.isbn = isbn
end
|
#language(language) ⇒ Object
92
93
94
|
# File 'lib/bindery/book_builder.rb', line 92
def language(language)
book.language = language
end
|
Allows grouping metadata elements together in a named block within the book specification. Use of this method is not necessary; all of the metadata methods can be called directly on the BookBuilder instance. It is usually best, though, to have them clearly grouped within a metadata block.
53
54
55
|
# File 'lib/bindery/book_builder.rb', line 53
def metadata
yield self
end
|
57
58
59
60
61
62
63
64
|
# File 'lib/bindery/book_builder.rb', line 57
def metadata_element(name, value, options={})
name_sym = name.to_sym
if Metadata[name_sym] == :special
book.metadata << Bindery::Book::Metadata.new(name_sym, value, options)
else
book.metadata << Bindery::Book::DublinMetadata.new(name_sym, value, options)
end
end
|
#output(basename) ⇒ Object
36
37
38
39
|
# File 'lib/bindery/book_builder.rb', line 36
def output(basename)
raise "output already set to #{book.output}" unless book.output.nil?
book.output = basename.to_s
end
|
#subtitle(subtitle) ⇒ Object
88
89
90
|
# File 'lib/bindery/book_builder.rb', line 88
def subtitle(subtitle)
book.subtitle = subtitle
end
|
#title(title) ⇒ Object
84
85
86
|
# File 'lib/bindery/book_builder.rb', line 84
def title(title)
book.title = title
end
|
#url(url) ⇒ Object
TODO: Most of these could be switched to be general metadata objects. Should they be?
76
77
78
|
# File 'lib/bindery/book_builder.rb', line 76
def url(url)
book.url = url
end
|