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: CFI, ContentDocument, OCF, Publication
Constant Summary collapse
- VERSION =
"0.2.4"
Class Method Summary collapse
-
.parse(filepath, **options) ⇒ EPUB
Parse an EPUB file.
Instance Method Summary collapse
-
#initialize(filepath, **options) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Constructor Details
#initialize(filepath, **options) ⇒ Parser
Returns a new instance of Parser.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/epub/parser.rb', line 44 def initialize(filepath, **) path_is_uri = ([:container_adapter] == EPUB::OCF::PhysicalContainer::UnpackedURI or [:container_adapter] == :UnpackedURI or EPUB::OCF::PhysicalContainer.adapter == EPUB::OCF::PhysicalContainer::UnpackedURI) raise "File #{filepath} not readable" if !path_is_uri and !File.readable_real?(filepath) @filepath = path_is_uri ? filepath : File.realpath(filepath) @book = create_book() @book.epub_file = @filepath if [:container_adapter] adapter = [:container_adapter] @book.container_adapter = adapter end end |
Class Method Details
.parse(filepath, **options) ⇒ EPUB
Parse an EPUB file
39 40 41 |
# File 'lib/epub/parser.rb', line 39 def parse(filepath, **) new(filepath, ).parse end |
Instance Method Details
#parse ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/epub/parser.rb', line 61 def parse @book.container_adapter.open @filepath do |container| @book.ocf = OCF.parse(container) @book.package = Publication.parse(container, @book.rootfile_path) end @book end |