Skip to content

Commit

Permalink
Fix: get cover from malformed epubs
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandoalmeida committed Oct 27, 2012
1 parent abed835 commit 99d1258
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/epub-reader/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ def toc
def cover
cover_meta = metadata.css('[name="cover"]')
meta_content = cover_meta.size == 1 ? cover_meta.attr('content') : nil
cover_content = meta_content || manifest.css('[properties="cover-image"]').attr('id').to_s
relative_content_path + (cover_content.to_s.match(/\.(gif|jpe?g|png)/) ? cover_content : resources.css("##{cover_content}").attr('href').to_s)
cover_tag = meta_content || manifest.css('[properties="cover-image"]')
cover_content = cover_tag.size > 0 ? cover_tag.attr('id').to_s : nil
cover_content ? relative_content_path + (cover_content.to_s.match(/\.(gif|jpe?g|png)/) ? cover_content : resources.css("##{cover_content}").attr('href').to_s) : ""
end

# TODO: to parse
Expand Down
2 changes: 1 addition & 1 deletion lib/epub-reader/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Epub
class Reader
VERSION = "0.0.7"
VERSION = "0.0.8"
end
end
6 changes: 3 additions & 3 deletions teste.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
`rake install`
# `rake install`
require 'rubygems'
require 'epub-reader'

hd = '/home/fernando/trabalho/livros_e_apostilas/EPUB/hd.epub'
hd = '/home/fernando/Dropbox/trabalho/livros_e_apostilas/EPUB/e_book_Marketing.epub'

f1 = Epub::Reader.open(hd)

puts f1.title
puts f1.cover

0 comments on commit 99d1258

Please sign in to comment.