Class: Thornbed::Providers::Memegenerator

Inherits:
Provider
  • Object
show all
Defined in:
lib/thornbed/providers/memegenerator.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

#initializeMemegenerator

Returns a new instance of Memegenerator.



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

def initialize
  self.pattern = /^http(s)?:\/\/(cdn\.)?memegenerator\.net\/instance(s)?\/(\d+x\/)?\d+(\.jpg)?(\?[\w\W]*)?$/
end

Instance Attribute Details

#patternObject

Returns the value of attribute pattern.



6
7
8
# File 'lib/thornbed/providers/memegenerator.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
# File 'lib/thornbed/providers/memegenerator.rb', line 12

def get(url)
  raise Thornbed::NotValid, url if !valid?(url)
  url = URI.parse(url)
  ptype = "jpg"
  pic_id = /(\d+x\/)?\d+(\.jpg)?(\?[\w\W]*)?$/.match(url.path)
  {
    "url" => "http://cdn.memegenerator.net/instances/400x/#{pic_id}.#{ptype}",
    "type" => "photo",
    "provider_name" => provider_name,
    "provider_url" => "http://memegenerator.com",
    "thumbnail_url" => "http://cdn.memegenerator.net/instances/100x/#{pic_id}.#{ptype}",
    "version" => "1.0",
    "page" => "http://memegenerator.net/instance/#{pic_id}",
    "width" => nil,
    "height" => nil
  }
end