Skip to content

Commit

Permalink
Validates if cover file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandoalmeida committed Dec 19, 2012
1 parent ee8816c commit 02c943a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion lib/epub-reader/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Package

def initialize(rootfile, file)
@rootfile = rootfile
@file = file
@package = get_package_content(file)
@xml = Nokogiri::XML(@package).remove_namespaces!
end
Expand Down Expand Up @@ -110,7 +111,14 @@ 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_path = (cover_content.to_s.match(/\.(gif|jpe?g|png)/) ? cover_content : resources.css("##{cover_content}").attr('href').to_s)
if cover_exist?(relative_content_path + cover_path)
relative_content_path + cover_path
elsif cover_exist?(relative_content_path + "Images/" + cover_path)
relative_content_path + "Images/" + cover_path
else
""
end
rescue
""
end
Expand Down Expand Up @@ -141,6 +149,14 @@ def get_package_content(file)
end
end

def cover_exist?(path)
begin
!!@file.find_entry(path)
rescue
false
end
end

def root
@xml.css('package')
end
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.8"
VERSION = "0.0.9"
end
end

0 comments on commit 02c943a

Please sign in to comment.