Class: ImgurUrl::Image
- Inherits:
-
Object
- Object
- ImgurUrl::Image
- Defined in:
- lib/imgur_url/image.rb
Constant Summary collapse
- SIZES =
{ :small => 's', :thumb => 't', :box => 'b', :medium => 'm', :large => 'l', :huge => 'h', :original => '', }
- IGNORE_PATHS =
%w[ gallery removalrequest ]
Class Method Summary collapse
Instance Method Summary collapse
- #download_url ⇒ Object
- #id ⇒ Object
-
#initialize(url) ⇒ Image
constructor
A new instance of Image.
- #permalink_url ⇒ Object
- #url(size = :original) ⇒ Object
Constructor Details
#initialize(url) ⇒ Image
Returns a new instance of Image.
22 23 24 25 |
# File 'lib/imgur_url/image.rb', line 22 def initialize(url) @original_url = url raise InvalidUrl unless id.present? && !IGNORE_PATHS.include?(id) end |
Class Method Details
.from_id(id) ⇒ Object
18 19 20 |
# File 'lib/imgur_url/image.rb', line 18 def self.from_id(id) self.new("http://imgur.com/#{id}") end |
Instance Method Details
#download_url ⇒ Object
41 42 43 |
# File 'lib/imgur_url/image.rb', line 41 def download_url @download_url ||= "http://imgur.com/download/#{id}" end |
#id ⇒ Object
27 28 29 |
# File 'lib/imgur_url/image.rb', line 27 def id @id ||= @original_url.match(%r{^http://(?:i\.)?imgur\.com/(?:download/)?([^.#?/]{5,})}).andand[1] end |
#permalink_url ⇒ Object
37 38 39 |
# File 'lib/imgur_url/image.rb', line 37 def permalink_url @permalink_url ||= "http://imgur.com/#{id}" end |
#url(size = :original) ⇒ Object
31 32 33 34 35 |
# File 'lib/imgur_url/image.rb', line 31 def url(size = :original) raise InvalidSize unless SIZES[size] @direct_urls ||= {} @direct_urls[size] ||= "http://i.imgur.com/#{id}#{SIZES[size]}.jpg" end |