Class: Thornbed::Providers::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/thornbed/provider.rb

Direct Known Subclasses

Imgur, Memecrunch, Memegenerator, NineGag, QuickMeme

Constant Summary collapse

USER_AGENT =
"Thornbed/#{Thornbed::VERSION}"

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.providersObject (readonly)

Returns the value of attribute providers.



11
12
13
# File 'lib/thornbed/provider.rb', line 11

def providers
  @providers
end

Class Method Details

.inherited(subclass) ⇒ Object



14
15
16
# File 'lib/thornbed/provider.rb', line 14

def self.inherited(subclass)
  providers << subclass
end

Instance Method Details

#get(url) ⇒ Object

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/thornbed/provider.rb', line 31

def get(url)
  raise NotImplementedError, "Subclasses must implement a get method."
end

#patternObject

Raises:

  • (NotImplementedError)


18
19
20
21
# File 'lib/thornbed/provider.rb', line 18

def pattern
  raise NotImplementedError,
    'Subclasses must implement a pattern method'
end

#provider_nameObject



27
28
29
# File 'lib/thornbed/provider.rb', line 27

def provider_name
  self.class.to_s.split('::')[-1]
end

#valid?(url) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/thornbed/provider.rb', line 23

def valid?(url)
  !!pattern.match(url)
end