Class: EPUBInfo::Models::Cover
- Inherits:
-
Object
- Object
- EPUBInfo::Models::Cover
- Defined in:
- lib/epubinfo/models/cover.rb
Instance Attribute Summary collapse
-
#content_type ⇒ String
Content type of cover file.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parser) ⇒ Cover
constructor
A new instance of Cover.
-
#original_file_name ⇒ String
Original name of cover file.
-
#tempfile(&block) ⇒ File
Cover file Tempfile is used to enable access to cover file If block is passed, the tempfile is passed to it and closed after the block is executed cover.file do { |f| puts f.size } Otherwise user is responsible to unlink and close tempfile file = book.cover.file file.size file.close!.
Constructor Details
#initialize(parser) ⇒ Cover
Returns a new instance of Cover.
16 17 18 19 20 |
# File 'lib/epubinfo/models/cover.rb', line 16 def initialize(parser) @parser = parser @path = epub_cover_file_path @content_type = epub_cover_content_type end |
Instance Attribute Details
#content_type ⇒ String
Content type of cover file
30 31 32 |
# File 'lib/epubinfo/models/cover.rb', line 30 def content_type @content_type end |
Class Method Details
Instance Method Details
#original_file_name ⇒ String
Original name of cover file
24 25 26 |
# File 'lib/epubinfo/models/cover.rb', line 24 def original_file_name File.basename(@path) if @path end |
#tempfile(&block) ⇒ File
Cover file Tempfile is used to enable access to cover file If block is passed, the tempfile is passed to it and closed after the block is executed
cover.file do { |f| puts f.size }
Otherwise user is responsible to unlink and close tempfile
file = book.cover.file
file.size
file.close!
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/epubinfo/models/cover.rb', line 49 def tempfile(&block) tempfile = Tempfile.new('epubinfo') tempfile.binmode cover_file = @parser.zip_file.read(zip_file_path) tempfile.write(cover_file) if block_given? yield tempfile tempfile.close! else # user is responsible for closing file tempfile end end |