Class: Epub::Reader
- Inherits:
-
Object
- Object
- Epub::Reader
- Defined in:
- lib/epub-reader/reader.rb,
lib/epub-reader/version.rb
Constant Summary collapse
- EPUB_MIMETYPE =
"application/epub+zip"- PACKAGE_MEDIATYPE =
"application/oebps-package+xml"- VERSION =
"0.0.9"
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#filepath ⇒ Object
readonly
Returns the value of attribute filepath.
Class Method Summary collapse
Instance Method Summary collapse
- #author ⇒ Object
- #container ⇒ Object
- #cover ⇒ Object
- #epub_version ⇒ Object
-
#initialize(f) ⇒ Reader
constructor
A new instance of Reader.
- #language ⇒ Object
- #mimetype ⇒ Object
-
#package(index = 0) ⇒ Object
Convenient method.
- #pages ⇒ Object
- #publication_date ⇒ Object
- #title ⇒ Object
- #toc ⇒ Object
- #uid ⇒ Object
Constructor Details
#initialize(f) ⇒ Reader
Returns a new instance of Reader.
9 10 11 12 13 14 |
# File 'lib/epub-reader/reader.rb', line 9 def initialize(f) raise(FileNotFoundError, "File not found") unless File.exists?(f) @filepath = f.to_s @file = EpubFile.new(f) raise(MalformedFileError, "Invalid EPUB file format") unless valid? end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
7 8 9 |
# File 'lib/epub-reader/reader.rb', line 7 def file @file end |
#filepath ⇒ Object (readonly)
Returns the value of attribute filepath.
7 8 9 |
# File 'lib/epub-reader/reader.rb', line 7 def filepath @filepath end |
Class Method Details
Instance Method Details
#author ⇒ Object
45 46 47 |
# File 'lib/epub-reader/reader.rb', line 45 def @author ||= package.creator end |
#container ⇒ Object
65 66 67 |
# File 'lib/epub-reader/reader.rb', line 65 def container @container ||= Container.new(self) end |
#cover ⇒ Object
69 70 71 |
# File 'lib/epub-reader/reader.rb', line 69 def cover @cover ||= package.cover end |
#epub_version ⇒ Object
33 34 35 |
# File 'lib/epub-reader/reader.rb', line 33 def epub_version @version ||= package.version end |
#language ⇒ Object
53 54 55 |
# File 'lib/epub-reader/reader.rb', line 53 def language @language ||= package.language end |
#mimetype ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/epub-reader/reader.rb', line 25 def mimetype @mimetype ||= begin file.get_input_stream('mimetype').read rescue nil end end |
#package(index = 0) ⇒ Object
Convenient method
90 91 92 |
# File 'lib/epub-reader/reader.rb', line 90 def package(index = 0) container.package(index) end |
#pages ⇒ Object
61 62 63 |
# File 'lib/epub-reader/reader.rb', line 61 def pages @pages ||= toc.pages end |
#publication_date ⇒ Object
49 50 51 |
# File 'lib/epub-reader/reader.rb', line 49 def publication_date @publication_date ||= package.date end |
#title ⇒ Object
41 42 43 |
# File 'lib/epub-reader/reader.rb', line 41 def title @title ||= package.title end |
#toc ⇒ Object
57 58 59 |
# File 'lib/epub-reader/reader.rb', line 57 def toc @toc ||= Toc.new(package.toc, self) end |
#uid ⇒ Object
37 38 39 |
# File 'lib/epub-reader/reader.rb', line 37 def uid @uid ||= package.identifier end |