Class: MechanizeClip::TmpFile

Inherits:
Tempfile
  • Object
show all
Defined in:
lib/mechanize_clip.rb

Overview

Temfile capatible with paperclip

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typeObject (readonly)

Returns the value of attribute content_type.



9
10
11
# File 'lib/mechanize_clip.rb', line 9

def content_type
  @content_type
end

#pageObject (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_filenameObject



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