Skip to content

Commit

Permalink
restore ability to provide file path to parse method
Browse files Browse the repository at this point in the history
  • Loading branch information
artygus committed May 12, 2024
1 parent 8282c04 commit 63c6647
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/gepub/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ def self.rootfile_from_container(rootfile)
doc.css("#{defaultns}|rootfiles > #{defaultns}|rootfile")[0]['full-path']
end

# Parses existing EPUB2/EPUB3 files from an IO object, and creates new Book object.
# Parses existing EPUB2/EPUB3 files from an IO object or a file path and creates new Book object.
# book = self.parse(File.new('some.epub'))

def self.parse(io)
def self.parse(path_or_io)
files = {}
package = nil
package_path = nil
book = nil
Zip::File.open_buffer(io) do
Zip::File.open(path_or_io) do
|zip_file|
package, package_path = parse_container(zip_file, files)
check_consistency_of_package(package, package_path)
Expand Down
9 changes: 9 additions & 0 deletions spec/book_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,15 @@
expect(book.items.size).to eq 3
end
end

context 'file path' do
it 'loads book and returns GEPUB::Book object' do
filepath = File.join(File.dirname(__FILE__), 'fixtures', 'testdata', 'wasteland-20120118.epub')
book = GEPUB::Book.parse(filepath)
expect(book).to be_instance_of GEPUB::Book
expect(book.items.size).to eq 6
end
end
end
end
end

0 comments on commit 63c6647

Please sign in to comment.