We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

mdi on 06/25/08


Tagged

textmate ruby mime-types


Versions (?)


Url.image


Published in: Ruby 


  1. require 'net/http'
  2.  
  3. module Url
  4. IMAGE_MIME_TYPES = ['image/jpeg', 'image/jpg', 'image/pjpeg', 'image/gif', 'image/png', 'image/x-png']
  5.  
  6. def self.image?(url)
  7. url = URI.parse(url)
  8. Net::HTTP.start(url.host, url.port) do |http|
  9. res = http.head(url.path)
  10. IMAGE_MIME_TYPES.include?(res.content_type) if Net::HTTPSuccess
  11. end
  12. end
  13. end

Report this snippet 

You need to login to post a comment.