Class: Kindler::Book
- Inherits:
-
Object
- Object
- Kindler::Book
- Defined in:
- lib/kindler.rb
Defined Under Namespace
Classes: KindlerError
Constant Summary collapse
- TMP_DIR =
'kindler_generated_mobi'
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#title ⇒ Object
Returns the value of attribute title.
-
#urls ⇒ Object
Returns the value of attribute urls.
Instance Method Summary collapse
-
#add_url(url, options = {}) ⇒ Object
add url to book.
-
#generate(title = '') ⇒ Object
generate books by given urls.
-
#initialize(options = {}) ⇒ Book
constructor
availabel options.
-
#mobi_generated? ⇒ Boolean
check mobi file is generated already.
Constructor Details
#initialize(options = {}) ⇒ Book
availabel options
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kindler.rb', line 21 def initialize(={}) @urls = [:urls] || {} @title = [:title] || '' @output_dir = [:output_dir] || './' @keep_image = [:keep_image] || true @debug = [:debug] raise KindlerError.new("urls option could not be empty") if @urls.empty? @author = [:author] || '' @images = [] @doc_infos = {} # init doc infos by url @urls.each {|url| @doc_infos[url]= {} } end |
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author.
11 12 13 |
# File 'lib/kindler.rb', line 11 def @author end |
#title ⇒ Object
Returns the value of attribute title.
11 12 13 |
# File 'lib/kindler.rb', line 11 def title @title end |
#urls ⇒ Object
Returns the value of attribute urls.
11 12 13 |
# File 'lib/kindler.rb', line 11 def urls @urls end |
Instance Method Details
#add_url(url, options = {}) ⇒ Object
add url to book
39 40 41 42 43 |
# File 'lib/kindler.rb', line 39 def add_url(url,={}) return if @doc_infos[url] @urls << url @doc_infos[url] = {} end |
#generate(title = '') ⇒ Object
generate books by given urls
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kindler.rb', line 46 def generate(title='') make_generated_dirs # generate generate_html localize_images generate_toc generate_opf generate_ncx write_to_disk kindlegen # clear end |
#mobi_generated? ⇒ Boolean
check mobi file is generated already
60 61 62 |
# File 'lib/kindler.rb', line 60 def mobi_generated? File.exist? "#{tmp_dir}/#{@title}.mobi" end |