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.



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

def initialize(ua)
  @ua = ua
end

Instance Attribute Details

#uaObject (readonly)

Returns the value of attribute ua.



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

def ua
  @ua
end

Class Method Details

.bot_exceptionsObject



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

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

.botsObject



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

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

.detect_empty_ua!Object



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

def self.detect_empty_ua!
  @detect_empty_ua = true
end

.detect_empty_ua?Boolean

Returns:

  • (Boolean)


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

def self.detect_empty_ua?
  @detect_empty_ua
end

.search_enginesObject



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

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

Instance Method Details

#bot?Boolean

Returns:

  • (Boolean)


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

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

#nameObject



41
42
43
44
45
# File 'lib/browser/bot.rb', line 41

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)


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

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