Module: Legitbot
- Defined in:
- lib/legitbot/ias.rb,
lib/legitbot/you.rb,
lib/legitbot/bing.rb,
lib/legitbot/meta.rb,
lib/legitbot/apple.rb,
lib/legitbot/baidu.rb,
lib/legitbot/ahrefs.rb,
lib/legitbot/amazon.rb,
lib/legitbot/google.rb,
lib/legitbot/openai.rb,
lib/legitbot/oracle.rb,
lib/legitbot/yandex.rb,
lib/legitbot/blexbot.rb,
lib/legitbot/twitter.rb,
lib/legitbot/version.rb,
lib/legitbot/botmatch.rb,
lib/legitbot/facebook.rb,
lib/legitbot/legitbot.rb,
lib/legitbot/petalbot.rb,
lib/legitbot/pinterest.rb,
lib/legitbot/dataforseo.rb,
lib/legitbot/duckduckgo.rb,
lib/legitbot/marginalia.rb,
lib/legitbot/config/resolver.rb,
lib/legitbot/validators/domains.rb,
lib/legitbot/validators/ip_ranges.rb
Overview
:nodoc:
Defined Under Namespace
Modules: Config, MetaIpRanges, Validators Classes: Ahrefs, Amazon, Apple, BLEXBot, Baidu, Bing, BotMatch, DataForSEO, DuckDuckGo, Facebook, GPTBot, Google, Ias, Marginalia, Meta, OpenAIChat, OpenAISearch, Oracle, Petalbot, Pinterest, Twitter, Yandex, You
Constant Summary collapse
- VERSION =
'1.11.2'
Class Attribute Summary collapse
-
.resolver_config ⇒ Object
Returns the value of attribute resolver_config.
Class Method Summary collapse
-
.bot(user_agent, ip) ⇒ Object
Lookup a bot based on its signature from
User-Agent
header. -
.rule(clazz, fragments) ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity.
Class Attribute Details
.resolver_config ⇒ Object
Returns the value of attribute resolver_config.
9 10 11 |
# File 'lib/legitbot/legitbot.rb', line 9 def resolver_config @resolver_config end |
Class Method Details
.bot(user_agent, ip) ⇒ 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
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/legitbot/legitbot.rb', line 22 def self.bot(user_agent, ip) bots = @rules .select { |rule| rule[:fragments].any? { |f| user_agent.index f } } .map { |rule| rule[:class].new(ip) } selected = bots.select(&: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
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
38 39 40 |
# File 'lib/legitbot/legitbot.rb', line 38 def self.rule(clazz, fragments) @rules << { class: clazz, fragments: fragments } end |