Class: SnipSnap::Image

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/snip_snap/image.rb

Constant Summary collapse

MIME_TYPES =
%w(image/jpeg image/gif image/pjpeg image/png)
EXTENSIONS =
%w(jpeg jpg gif png)

Instance Method Summary collapse

Methods included from Client

included

Instance Method Details

#extensionObject



15
16
17
18
19
20
# File 'lib/snip_snap/image.rb', line 15

def extension
  uri = URI.parse(response.last_effective_url)
  extension = File.extname(uri.path).sub(/./, '')
  
  extension unless extension == ''
end

#image?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/snip_snap/image.rb', line 22

def image?
  MIME_TYPES.include?(mime_type) || EXTENSIONS.include?(extension)
end

#image_urlObject



26
27
28
# File 'lib/snip_snap/image.rb', line 26

def image_url
  response.last_effective_url if image?
end

#mime_typeObject



11
12
13
# File 'lib/snip_snap/image.rb', line 11

def mime_type
  response.content_type
end