Class: MechanizeClip::TmpFile
- Inherits:
-
Tempfile
- Object
- Tempfile
- MechanizeClip::TmpFile
- Defined in:
- lib/mechanize_clip.rb
Overview
Temfile capatible with paperclip
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(page) ⇒ TmpFile
constructor
A new instance of TmpFile.
- #original_filename ⇒ Object
Constructor Details
#initialize(page) ⇒ TmpFile
Returns a new instance of TmpFile.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mechanize_clip.rb', line 12 def initialize page @page = page ext = File.extname(self.original_filename) name = File.basename(self.original_filename, ext) super([name, ext]) self.binmode content = @page.content if String === content self.write content else until content.eof? do self.write content.read 16384 end end self.flush self.rewind @content_type = @page.response['content-type'] end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
9 10 11 |
# File 'lib/mechanize_clip.rb', line 9 def content_type @content_type end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
10 11 12 |
# File 'lib/mechanize_clip.rb', line 10 def page @page end |
Instance Method Details
#original_filename ⇒ Object
31 32 33 34 35 36 |
# File 'lib/mechanize_clip.rb', line 31 def original_filename @original_filename ||= begin match = @page.uri.path.match(/^.*\/(.+\..+)$/) match ? match[1] : @page.filename end end |