Class: Kindler::Book

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

Defined Under Namespace

Classes: KindlerError

Constant Summary collapse

TMP_DIR =
'kindler_generated_mobi'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Book

availabel options

Parameters:

  • options (Hash) (defaults to: {})
  • urls (Hash)

    a customizable set of options

  • title (Hash)

    a customizable set of options

  • output_dir (Hash)

    a customizable set of options

  • debug (Hash)

    a customizable set of options

  • keep_image (Hash)

    a customizable set of options

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/kindler.rb', line 21

def initialize(options={})
	@urls = options[:urls] || {}
	@title = options[:title] || ''
	@output_dir = options[:output_dir] || './'
	@keep_image = options[:keep_image] || true
	@debug = options[:debug]
	raise KindlerError.new("urls option could not be empty") if @urls.empty?
	@author = options[:author] || ''
	@images = []
	@doc_infos = {}
	# init doc infos by url
	@urls.each {|url| @doc_infos[url]= {} }
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



11
12
13
# File 'lib/kindler.rb', line 11

def author
  @author
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/kindler.rb', line 11

def title
  @title
end

#urlsObject

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

Parameters:

  • url (String)

    url to add to book

  • options (Hash) (defaults to: {})
  • section (Hash)

    a customizable set of options



39
40
41
42
43
# File 'lib/kindler.rb', line 39

def add_url(url,options={})
	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

Returns:

  • (Boolean)


60
61
62
# File 'lib/kindler.rb', line 60

def mobi_generated?
	File.exist? "#{tmp_dir}/#{@title}.mobi"
end