Module: ImageURL

Defined in:
lib/imageurl.rb

Class Method Summary collapse

Class Method Details

.image_url_for(url, options = {:format => :medium}) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/imageurl.rb', line 8

def image_url_for(url, options = {:format => :medium} )
  raise ArgumentError unless valid_url?(url)

  url = "http://" + url unless url =~ /^http:\/\//

  if yfrog_url?(url)
    suffix = case options.delete(:format)
      when :medium; ":medium"
      when :iphone; ":iphone"
      when :small;  ":small"
      when :thumb;  ":small"
    end
    raise ArgumentError unless suffix
    url + suffix
  else
    "https://twitpic.com/show/large/#{url.gsub(/^.*\//, "")}"
  end
end

.valid_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/imageurl.rb', line 4

def valid_url?(url)
  yfrog_url?(url) || twitpic_url?(url)
end