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.
28 29 30 |
# File 'lib/browser/bot.rb', line 28 def initialize(ua) @ua = ua end |
Instance Attribute Details
#ua ⇒ Object (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_exceptions ⇒ Object
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 |
.bots ⇒ Object
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
8 9 10 |
# File 'lib/browser/bot.rb', line 8 def self.detect_empty_ua? @detect_empty_ua end |
Instance Method Details
#bot? ⇒ Boolean
32 33 34 |
# File 'lib/browser/bot.rb', line 32 def bot? bot_with_empty_ua? || (!bot_exception? && detect_bot?) end |
#name ⇒ Object
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
36 37 38 |
# File 'lib/browser/bot.rb', line 36 def search_engine? self.class.search_engines.any? {|key, _| downcased_ua.include?(key) } end |