Class: Imgurapi::FileType
- Inherits:
-
Object
- Object
- Imgurapi::FileType
- Defined in:
- lib/imgurapi/file_type.rb
Constant Summary collapse
- GIF =
/^GIF8/
- PNG =
Regexp.new("^\x89PNG".force_encoding('binary'))
- JPG =
Regexp.new("^\xff\xd8\xff\xe0\x00\x10JFIF".force_encoding('binary'))
- JPG2 =
Regexp.new("^\xff\xd8\xff\xe1(.*){2}Exif".force_encoding('binary'))
Instance Method Summary collapse
- #image? ⇒ Boolean
-
#initialize(path) ⇒ FileType
constructor
A new instance of FileType.
- #mime_type ⇒ Object
- #url? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ FileType
Returns a new instance of FileType.
9 10 11 |
# File 'lib/imgurapi/file_type.rb', line 9 def initialize(path) @path = path end |
Instance Method Details
#image? ⇒ Boolean
26 27 28 |
# File 'lib/imgurapi/file_type.rb', line 26 def image? !!mime_type end |
#mime_type ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/imgurapi/file_type.rb', line 13 def mime_type case IO.read(@path, 10) when GIF 'image/gif' when PNG 'image/png' when JPG 'image/jpeg' when JPG2 'image/jpeg' end end |
#url? ⇒ Boolean
30 31 32 |
# File 'lib/imgurapi/file_type.rb', line 30 def url? !!(@path =~ %r(^(http://|https://|ftp://))) end |