Class: Thornbed::Providers::Memecrunch

Inherits:
Provider
  • Object
show all
Defined in:
lib/thornbed/providers/memecrunch.rb

Constant Summary

Constants inherited from Provider

Provider::USER_AGENT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Provider

inherited, #provider_name, #valid?

Constructor Details

#initializeMemecrunch

Returns a new instance of Memecrunch.



8
9
10
# File 'lib/thornbed/providers/memecrunch.rb', line 8

def initialize
  self.pattern = /^http(s)?:\/\/memecrunch.com\/meme\/\w+\/[\w-]+(\/image.png)?(\?w=\d+)?$/
end

Instance Attribute Details

#patternObject

Returns the value of attribute pattern.



6
7
8
# File 'lib/thornbed/providers/memecrunch.rb', line 6

def pattern
  @pattern
end

Instance Method Details

#get(url) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/thornbed/providers/memecrunch.rb', line 12

def get(url)
  raise Thornbed::NotValid, url if !valid?(url)
  url = URI.parse(url)

  res = /([A-Z]{4,})\/([\w-]+)/.match(url.path)
  pic_id = res[1]
  slug = res[2]

  {
    "url" => "http://memecrunch.com/meme/#{pic_id}/#{slug}/image.png",
    "type" => "photo",
    "provider_name" => provider_name,
    "provider_url" => "http://memecrunch.com",
    "thumbnail_url" => "http://memecrunch.com/meme/#{pic_id}/#{slug}/image.png?w=75",
    "version" => "1.0",
    "page" => "http://memecrunch.com/meme/#{pic_id}/#{slug}/",
    "width" => nil,
    "height" => nil
  }
end