Class: EPUB::Parser
- Inherits:
-
Object
- Object
- EPUB::Parser
- Defined in:
- lib/epub/parser.rb,
lib/epub/parser/ocf.rb,
lib/epub/parser/utils.rb,
lib/epub/parser/version.rb,
lib/epub/parser/publication.rb,
lib/epub/parser/content_document.rb
Defined Under Namespace
Modules: Utils Classes: ContentDocument, OCF, Publication
Constant Summary collapse
- VERSION =
"0.1.6"
Class Method Summary collapse
-
.parse(filepath, options = {}) ⇒ EPUB
Parse an EPUB file.
- .parse_io(io_stream, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(datasource, options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
-
#parse_io ⇒ Object
unnecessary, but desirable maybe?.
Constructor Details
#initialize(datasource, options = {}) ⇒ Parser
Returns a new instance of Parser.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/epub/parser.rb', line 46 def initialize(datasource, = {}) if [:io] raise "IO source not readable" unless datasource.respond_to?(:read) @io_stream = datasource @book = create_book file = Tempfile.new('epub_string') file.write(@io_stream) @filepath = file.path @book.epub_file = @filepath else raise "File #{datasource} not readable" unless File.readable_real? datasource @filepath = File.realpath datasource @book = create_book @book.epub_file = @filepath end end |
Class Method Details
.parse(filepath, options = {}) ⇒ EPUB
Parse an EPUB file
37 38 39 |
# File 'lib/epub/parser.rb', line 37 def parse(filepath, = {}) new(filepath, ).parse end |
.parse_io(io_stream, options = {}) ⇒ Object
41 42 43 |
# File 'lib/epub/parser.rb', line 41 def parse_io(io_stream, = {}) new(io_stream, .merge(io: true)).parse end |
Instance Method Details
#parse ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/epub/parser.rb', line 65 def parse Zip::Archive.open @filepath do |zip| @book.ocf = OCF.parse(zip) @book.package = Publication.parse(zip, @book.ocf.container.rootfile.full_path.to_s) end @book end |
#parse_io ⇒ Object
unnecessary, but desirable maybe?
74 75 76 77 78 79 80 81 |
# File 'lib/epub/parser.rb', line 74 def parse_io # unnecessary, but desirable maybe? Zip::Archive.open_buffer @io_stream do |zip| @book.ocf = OCF.parse(zip) @book.package = Publication.parse(zip, @book.ocf.container.rootfile.full_path.to_s) end @book end |