Class: SearchBot

Inherits:
Agent show all
Defined in:
lib/ntail/http_user_agent.rb

Constant Summary collapse

KNOWN_SEARCH_BOTS =

Mozilla/5.0 (compatible; Googlebot/2.1; www.google.com/bot.html) Googlebot-Image/1.0 msnbot/2.0b (search.msn.com/msnbot.htm) msnbot/2.0b (+search.msn.com/msnbot.htm). msnbot/2.0b (+search.msn.com/msnbot.htm)._ Mozilla/5.0 (compatible; Yahoo! Slurp/3.0; help.yahoo.com/help/us/ysearch/slurp) Pingdom.com_bot_version_1.4_(www.pingdom.com/) ia_archiver (+www.alexa.com/site/help/webmasters; [email protected]) Mozilla/5.0 (compatible; YandexBot/3.0; +yandex.com/bots)

[
   GOOGLE_BOT = Regexp.compile('Googlebot.*\/'),
      MSN_BOT = Regexp.compile('msnbot\/'),
    YAHOO_BOT = Regexp.compile('Yahoo! Slurp\/?'),
  PINGDOM_BOT = Regexp.compile('Pingdom.com_bot_version_'),
    ALEXA_BOT = Regexp.compile('ia_archiver'),
   YANDEX_BOT = Regexp.compile('YandexBot\/'),
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ SearchBot

Returns a new instance of SearchBot.



46
47
48
49
50
# File 'lib/ntail/http_user_agent.rb', line 46

def initialize(string)
  super string
  @name = self.class.name_for_user_agent(string)
  @os = self.class.os_for_user_agent(string)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



43
44
45
# File 'lib/ntail/http_user_agent.rb', line 43

def name
  @name
end

#osObject

Returns the value of attribute os.



44
45
46
# File 'lib/ntail/http_user_agent.rb', line 44

def os
  @os
end

Class Method Details

.name_for_user_agent(string) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ntail/http_user_agent.rb', line 52

def self.name_for_user_agent string
  case string
    when  GOOGLE_BOT then :googlebot
    when     MSN_BOT then :msnbot
    when   YAHOO_BOT then :yahoo_slurp
    when   ALEXA_BOT then :ia_archiver
    when PINGDOM_BOT then :pingdom_bot
    when  YANDEX_BOT then :yandex_bot
    else super(string)
  end
end

.os_for_user_agent(string) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ntail/http_user_agent.rb', line 64

def self.os_for_user_agent string
  case string
    when  GOOGLE_BOT then :"google.com"
    when     MSN_BOT then :"msn.com"
    when   YAHOO_BOT then :"yahoo.com"
    when   ALEXA_BOT then :"alexa.com"
    when PINGDOM_BOT then :"pingdom.com"
    when  YANDEX_BOT then :"yandex.com"
    else super(string)
  end
end

.search_bot?(http_user_agent) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/ntail/http_user_agent.rb', line 39

def self.search_bot?(http_user_agent)
  !KNOWN_SEARCH_BOTS.detect { |bot| bot.match(http_user_agent) }.nil?
end

Instance Method Details

#search_bot?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/ntail/http_user_agent.rb', line 14

def search_bot?
  true
end