class Browser::Bot
Constants
- GENERIC_NAME
Attributes
browser[R]
ua[R]
Public Class Methods
bot_exceptions()
click to toggle source
# File lib/browser/bot.rb, line 27 def self.bot_exceptions @bot_exceptions ||= load_yaml("bot_exceptions.yml") end
bots()
click to toggle source
# File lib/browser/bot.rb, line 23 def self.bots @bots ||= load_yaml("bots.yml") end
default_matchers()
click to toggle source
# File lib/browser/bot.rb, line 11 def self.default_matchers [ EmptyUserAgentMatcher, KnownBotsMatcher, KeywordMatcher ] end
load_yaml(path)
click to toggle source
# File lib/browser/bot.rb, line 19 def self.load_yaml(path) YAML.load_file(Browser.root.join(path)) end
matchers()
click to toggle source
# File lib/browser/bot.rb, line 7 def self.matchers @matchers ||= default_matchers end
new(ua)
click to toggle source
# File lib/browser/bot.rb, line 43 def initialize(ua) @ua = ua.downcase.strip @browser = Browser.new(@ua) end
search_engines()
click to toggle source
# File lib/browser/bot.rb, line 31 def self.search_engines @search_engines ||= load_yaml("search_engines.yml") end
why?(ua)
click to toggle source
# File lib/browser/bot.rb, line 35 def self.why?(ua) ua = ua.downcase.strip browser = Browser.new(ua) matchers.find {|matcher| matcher.call(ua, browser) } end
Public Instance Methods
bot?()
click to toggle source
# File lib/browser/bot.rb, line 48 def bot? !bot_exception? && detect_bot? end
name()
click to toggle source
# File lib/browser/bot.rb, line 60 def name return unless bot? self.class.bots.find {|key, _| ua.include?(key) }&.last || GENERIC_NAME end
search_engine?()
click to toggle source
# File lib/browser/bot.rb, line 56 def search_engine? self.class.search_engines.any? {|key, _| ua.include?(key) } end
why?()
click to toggle source
# File lib/browser/bot.rb, line 52 def why? self.class.matchers.find {|matcher| matcher.call(ua, self) } end
Private Instance Methods
bot_exception?()
click to toggle source
# File lib/browser/bot.rb, line 66 def bot_exception? self.class.bot_exceptions.any? {|key| ua.include?(key) } end
detect_bot?()
click to toggle source
# File lib/browser/bot.rb, line 70 def detect_bot? self.class.matchers.any? {|matcher| matcher.call(ua, browser) } end