class Browser::Bot
Attributes
ua[R]
Public Class Methods
bot_exceptions()
click to toggle source
# File lib/browser/bot.rb, line 16 def self.bot_exceptions @bot_exceptions ||= YAML .load_file(Browser.root.join("bot_exceptions.yml")) end
bots()
click to toggle source
# File lib/browser/bot.rb, line 12 def self.bots @bots ||= YAML.load_file(Browser.root.join("bots.yml")) end
detect_empty_ua!()
click to toggle source
# File lib/browser/bot.rb, line 4 def self.detect_empty_ua! @detect_empty_ua = true end
detect_empty_ua?()
click to toggle source
# File lib/browser/bot.rb, line 8 def self.detect_empty_ua? @detect_empty_ua end
new(ua)
click to toggle source
# File lib/browser/bot.rb, line 28 def initialize(ua) @ua = ua end
search_engines()
click to toggle source
# File lib/browser/bot.rb, line 21 def self.search_engines @search_engines ||= YAML .load_file(Browser.root.join("search_engines.yml")) end
Public Instance Methods
bot?()
click to toggle source
# File lib/browser/bot.rb, line 32 def bot? bot_with_empty_ua? || (!bot_exception? && detect_bot?) end
name()
click to toggle source
# File lib/browser/bot.rb, line 40 def name return unless bot? return "Generic Bot" if bot_with_empty_ua? self.class.bots.find {|key, _| downcased_ua.include?(key) }.last end
search_engine?()
click to toggle source
# File lib/browser/bot.rb, line 36 def search_engine? self.class.search_engines.any? {|key, _| downcased_ua.include?(key) } end
Private Instance Methods
bot_exception?()
click to toggle source
# File lib/browser/bot.rb, line 52 def bot_exception? self.class.bot_exceptions.any? {|key| downcased_ua.include?(key) } end
bot_with_empty_ua?()
click to toggle source
# File lib/browser/bot.rb, line 48 def bot_with_empty_ua? self.class.detect_empty_ua? && ua.strip == "" end
detect_bot?()
click to toggle source
# File lib/browser/bot.rb, line 56 def detect_bot? self.class.bots.any? {|key, _| downcased_ua.include?(key) } end
downcased_ua()
click to toggle source
# File lib/browser/bot.rb, line 60 def downcased_ua @downcased_ua ||= ua.downcase end