I have the following class:
require 'uri'
class Images
IMAGE_NOT_FOUND = '/images/no_image.gif'
attr_accessor :url
def initialize(parameters = {})
@url = parameters.fetch(:url, IMAGE_NOT_FOUND)
@url = IMAGE_NOT_FOUND unless @url =~/^#{URI::regexp}$/
end
end
holding URL
to image. I have checked some questions and add URL
validation, but I need to improve it validating URLs
pointing to images only.If validation fails, I want to use default image showing there is some issue.
Note, the current validation of the URL
is not working with relative paths. For example, the following url
is valid as image source /images/image1.png
but the current validation is not recognizing it.
Could anyone tell if this is possible using URI
?