Class: ActiveDevice::Bot
- Inherits:
-
Object
- Object
- ActiveDevice::Bot
- Defined in:
- lib/active_device/bot.rb
Constant Summary collapse
- PREFIX =
{ # Common prefixes (mozilla not included) :common => %w(opera), # Mobile browser prefixes :embedded => %w(blackberry docomo waptiger winwap), # Textmode browser prefixes :text => %w(elinks lynx retawq w3m/) << "links ", # Uncommon browser prefixes :rare => %w(advanced amaya amiga aplix cyberdog dillo galaxy genius hotjava ibm ibrowse icab ice klondike ncsa netsurf openwave reqwirelessweb sunrise worldwideweb), # These usually are not prefixes in their normal UA string :odd => %w(android avant firefox k-meleon konqueror netscape safari seamonkey) }
- ID =
{ :mobile => %w(^sec blackberry midp mmp netfront opera safari semc sonyericsson symbian up\\.browser up\\.link) << "windows ce", :moz_compatible => %w(amigavoyager antfresco aol applewebkit avant blackberry elaine gecko ibrowse icab khtml konqueror msie netfront netp netscape omniweb opera teleca voyager), :moz_platform => %w(amiga beos brew bsd danger dreamcast iphone ipod linux mac os/2 palm pda playstation ps2 ps3 psp risc star-blade sunos syllable symbian win x11 zx), :bot => %w(<a <script bot butterfly checker crawl daumoa del\\.icio\\.us depspid flycast heritrix httrack indexing ktxn larbin links-sql me\\.dium miro mozshot nutch odp-entries oneriot pbwf planetwide slurp spider survey thunderbird vermut) << "black widow" }
- REGEXP =
{ :prefix => /^#{PREFIX.values.flatten! * "|^"}/, :mobile => /#{ID[:mobile] * "|"}/, :moz_compatible => /#{ID[:moz_compatible] * "|"}/, :moz_platform => /#{ID[:moz_platform] * "|"}/, :bot => /#{ID[:bot] * "|"}/ }
Instance Method Summary collapse
Instance Method Details
#browser?(user_agent) ⇒ Boolean
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_device/bot.rb', line 43 def browser?(user_agent) # Empty string might be an anonymized browser return true if user_agent.nil? || user_agent =~ /^\s*$/ ua_lc = user_agent.downcase if ua_lc[0,7] == "mozilla" is_browser = ua_lc =~ REGEXP[:moz_compatible] || ua_lc =~ REGEXP[:moz_platform] else is_browser = ua_lc =~ REGEXP[:prefix] || ua_lc =~ REGEXP[:mobile] end is_browser = ua_lc[REGEXP[:bot]].nil? if is_browser return is_browser end |
#robot?(user_agent) ⇒ Boolean
39 40 41 |
# File 'lib/active_device/bot.rb', line 39 def robot?(user_agent) !browser?(user_agent) end |