Class: Thornbed::Providers::QuickMeme
- Defined in:
- lib/thornbed/providers/quickmeme.rb
Constant Summary
Constants inherited from Provider
Instance Attribute Summary collapse
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize ⇒ QuickMeme
constructor
A new instance of QuickMeme.
Methods inherited from Provider
inherited, #provider_name, #valid?
Constructor Details
#initialize ⇒ QuickMeme
Returns a new instance of QuickMeme.
8 9 10 |
# File 'lib/thornbed/providers/quickmeme.rb', line 8 def initialize self.pattern = /http(s)?:\/\/(i|t)?(\.)?(www\.)?(quickmeme.com|qkme.me)\/(meme\/)?(\w){6}(\/)?(.jpg)?((\?|#).*)?$/ end |
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
6 7 8 |
# File 'lib/thornbed/providers/quickmeme.rb', line 6 def pattern @pattern end |
Instance Method Details
#get(url) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/thornbed/providers/quickmeme.rb', line 12 def get(url) raise Thornbed::NotValid, url if !valid?(url) url = URI.parse(url) normal = /quickmeme.com/ =~ url.to_s direct = /qkme.me/ =~ url.to_s ptype = "jpg" if normal pic_id = /(\w){6}/.match(url.path) elsif direct pic_id = url.path[/(\w){6}(.jpg)?/ =~ url.path..6] else raise Thornbed::NotValid, url end { "url" => "http://i.qkme.me/#{pic_id}.#{ptype}", "type" => "photo", "provider_name" => provider_name, "provider_url" => "http://quickmeme.com", "thumbnail_url" => "http://t.qkme.me/#{pic_id}.#{ptype}", "version" => "1.0", "page" => "http://quickmeme.com/#{pic_id}/", "width" => nil, "height" => nil } end |