Module: Legitbot
- Defined in:
- lib/legitbot/bing.rb,
lib/legitbot/apple.rb,
lib/legitbot/baidu.rb,
lib/legitbot/ahrefs.rb,
lib/legitbot/google.rb,
lib/legitbot/yandex.rb,
lib/legitbot/version.rb,
lib/legitbot/botmatch.rb,
lib/legitbot/facebook.rb,
lib/legitbot/legitbot.rb,
lib/legitbot/pinterest.rb,
lib/legitbot/duckduckgo.rb
Defined Under Namespace
Classes: Ahrefs, Apple, Apple_as_Google, Baidu, Bing, BotMatch, DuckDuckGo, Facebook, Google, Pinterest, Yandex
Constant Summary collapse
- VERSION =
'0.3.0'
Class Method Summary collapse
-
.bot(userAgent, ip, resolver_config = nil) ⇒ Object
Lookup a bot based on its signature from
User-Agentheader. - .rule(clazz, fragments) ⇒ Object
Class Method Details
.bot(userAgent, ip, resolver_config = nil) ⇒ Object
Lookup a bot based on its signature from User-Agent header.
If a block given, passes the found bot to the block.
Returns nil if no bot found and a bot match instance otherwise. :yields: a found bot
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legitbot/legitbot.rb', line 13 def self.bot(userAgent, ip, resolver_config = nil) bots = @rules.select { |rule| rule[:fragments].any? {|f| userAgent.index f} }.map { |rule| rule[:class].new(ip, resolver_config) } selected = bots.select { |b| b.valid? }.first if bots.size > 1 selected = bots.last if selected.nil? if selected && block_given? yield selected else selected end end |
.rule(clazz, fragments) ⇒ Object
31 32 33 |
# File 'lib/legitbot/legitbot.rb', line 31 def self.rule(clazz, fragments) @rules << {:class => clazz, :fragments => fragments} end |