Module: Browser::Bots

Included in:
Browser
Defined in:
lib/browser/methods/bots.rb

Constant Summary collapse

BOTS =
Browser::Data::BOTS
SEARCH_ENGINES =
Browser::Data::SEARCH_ENGINES

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.detect_empty_ua!Object



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

def self.detect_empty_ua!
  @detect_empty_ua = true
end

.detect_empty_ua?Boolean

Returns:

  • (Boolean)


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

def self.detect_empty_ua?
  !!@detect_empty_ua
end

Instance Method Details

#bot?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/browser/methods/bots.rb', line 16

def bot?
  bot_with_empty_ua? || BOTS.any? {|key, _| ua.include?(key) }
end

#bot_nameObject



20
21
22
23
24
25
# File 'lib/browser/methods/bots.rb', line 20

def bot_name
  return 'Generic Bot' if bot_with_empty_ua?

  pair = BOTS.find {|key, _| ua.include?(key) }
  return pair ? pair.first : nil
end

#search_engine?Boolean

Returns:

  • (Boolean)


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

def search_engine?
  SEARCH_ENGINES.any? {|key, _| ua.include?(key) }
end