Class: Ranking

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

Constant Summary collapse

@@default_options =

careful, res_per_page doesn’t work with more than 10 for all search engines!

{ :limit => 200, :res_per_page => 10, :supported_engines => [:bing, :google, :googleUS, :yahoo] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ Ranking

keyword, url, limit



16
17
18
# File 'lib/uk_ranking.rb', line 16

def initialize(*options) # keyword, url, limit
  self.options = options.extract_options!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/uk_ranking.rb', line 32

def method_missing(method, *args, &block)
  engine = @@default_options[:supported_engines].find{ |name| ("from_" << name.to_s).match /#{method}/ }
  if engine
    @options.merge!({:engine => engine})
    send("from")
  else
    super(method, *args, &block)
  end
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#fromObject



26
27
28
29
30
# File 'lib/uk_ranking.rb', line 26

def from
  validate_options
  @finder ||= Finder.new
  @finder.find(@options)
end