Class: Browser::Bot
- Inherits:
-
Object
- Object
- Browser::Bot
- Defined in:
- lib/browser/bot.rb
Instance Attribute Summary collapse
-
#ua ⇒ Object
readonly
Returns the value of attribute ua.
Class Method Summary collapse
- .bot_exceptions ⇒ Object
- .bots ⇒ Object
- .detect_empty_ua! ⇒ Object
- .detect_empty_ua? ⇒ Boolean
- .search_engines ⇒ Object
Instance Method Summary collapse
- #bot? ⇒ Boolean
-
#initialize(ua) ⇒ Bot
constructor
A new instance of Bot.
- #name ⇒ Object
- #search_engine? ⇒ Boolean
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
#ua ⇒ Object (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_exceptions ⇒ Object
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 |
.bots ⇒ Object
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
9 10 11 |
# File 'lib/browser/bot.rb', line 9 def self.detect_empty_ua? @detect_empty_ua end |
Instance Method Details
#bot? ⇒ Boolean
33 34 35 |
# File 'lib/browser/bot.rb', line 33 def bot? bot_with_empty_ua? || (!bot_exception? && detect_bot?) end |
#name ⇒ Object
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
37 38 39 |
# File 'lib/browser/bot.rb', line 37 def search_engine? self.class.search_engines.any? {|key, _| downcased_ua.include?(key) } end |