Class: Browser::Bot

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ua) ⇒ Bot

Returns a new instance of Bot.



28
29
30
# File 'lib/browser/bot.rb', line 28

def initialize(ua)
  @ua = ua
end

Instance Attribute Details

#uaObject (readonly)

Returns the value of attribute ua.



26
27
28
# File 'lib/browser/bot.rb', line 26

def ua
  @ua
end

Class Method Details

.bot_exceptionsObject



16
17
18
19
# File 'lib/browser/bot.rb', line 16

def self.bot_exceptions
  @bot_exceptions ||= YAML
                      .load_file(Browser.root.join("bot_exceptions.yml"))
end

.botsObject



12
13
14
# File 'lib/browser/bot.rb', line 12

def self.bots
  @bots ||= YAML.load_file(Browser.root.join("bots.yml"))
end

.detect_empty_ua!Object



4
5
6
# File 'lib/browser/bot.rb', line 4

def self.detect_empty_ua!
  @detect_empty_ua = true
end

.detect_empty_ua?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/browser/bot.rb', line 8

def self.detect_empty_ua?
  @detect_empty_ua
end

.search_enginesObject



21
22
23
24
# File 'lib/browser/bot.rb', line 21

def self.search_engines
  @search_engines ||= YAML
                      .load_file(Browser.root.join("search_engines.yml"))
end

Instance Method Details

#bot?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/browser/bot.rb', line 32

def bot?
  bot_with_empty_ua? || (!bot_exception? && detect_bot?)
end

#nameObject



40
41
42
43
44
# 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?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/browser/bot.rb', line 36

def search_engine?
  self.class.search_engines.any? {|key, _| downcased_ua.include?(key) }
end