lib/epub/parser.rb in epub-parser-0.2.5 vs lib/epub/parser.rb in epub-parser-0.2.6
- old
+ new
@@ -44,25 +44,32 @@
def initialize(filepath, **options)
path_is_uri = (options[:container_adapter] == EPUB::OCF::PhysicalContainer::UnpackedURI or
options[: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)
+ raise "File #{filepath} not found" if
+ !path_is_uri and !File.exist?(filepath)
@filepath = path_is_uri ? filepath : File.realpath(filepath)
@book = create_book(options)
+ if File.directory? @filepath
+ @book.container_adapter = :UnpackedDirectory
+ end
@book.epub_file = @filepath
if options[:container_adapter]
- adapter = options[:container_adapter]
- @book.container_adapter = adapter
+ @book.container_adapter = options[:container_adapter]
end
end
def parse
@book.container_adapter.open @filepath do |container|
@book.ocf = OCF.parse(container)
- @book.package = Publication.parse(container, @book.rootfile_path)
+ @book.ocf.container.rootfiles.each {|rootfile|
+ package = Publication.parse(container, rootfile.full_path.to_s)
+ rootfile.package = package
+ @book.packages << package
+ package.book = @book
+ }
end
@book
end