Class: EpubBook

Inherits:
Object show all
Defined in:
lib/epub_book.rb

Overview

epub_book

处理EPUB书的类。

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ EpubBook

Returns a new instance of EpubBook.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/epub_book.rb', line 10

def initialize(filename,options={})
  raise '无效的文件' unless File.exists?(filename)
  @title = options[:title]
  @author = options[:author]
  @publisher = options[:publisher]
  @pubdate= options[:pubdate]
  @isbn = options[:isbn]

  text = Utils.extract_text_from_file(filename,'.epub')
  unless  Utils.detect_utf8(text)
    text = Utils.to_utf8(text)
  end
  text = preprocess_content(text)
  @outline, @content = extract_for_epub_text(text)
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



8
9
10
# File 'lib/epub_book.rb', line 8

def author
  @author
end

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'lib/epub_book.rb', line 8

def content
  @content
end

#isbnObject (readonly)

Returns the value of attribute isbn.



8
9
10
# File 'lib/epub_book.rb', line 8

def isbn
  @isbn
end

#outlineObject (readonly)

Returns the value of attribute outline.



8
9
10
# File 'lib/epub_book.rb', line 8

def outline
  @outline
end

#pubdateObject (readonly)

Returns the value of attribute pubdate.



8
9
10
# File 'lib/epub_book.rb', line 8

def pubdate
  @pubdate
end

#publisherObject (readonly)

Returns the value of attribute publisher.



8
9
10
# File 'lib/epub_book.rb', line 8

def publisher
  @publisher
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/epub_book.rb', line 8

def title
  @title
end

Instance Method Details

#to_doc_bookObject



30
31
32
# File 'lib/epub_book.rb', line 30

def to_doc_book
  build_doc_book(@outline,@content,{:title=>title,:publisher=>publisher,:pubdate=>pubdate,:author=>author,:isbn=>isbn})
end

#toc_to_textObject



26
27
28
# File 'lib/epub_book.rb', line 26

def toc_to_text
  outline
end