Module: NginxTail::HttpUserAgent

Defined in:
lib/ntail/http_user_agent.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/ntail/http_user_agent.rb', line 81

def self.included(base) # :nodoc:
  base.class_eval do

    def self.search_bot?(http_user_agent)
      SearchBot.search_bot?(http_user_agent)
    end 

    def self.to_agent(http_user_agent)
      if self.search_bot? http_user_agent
        SearchBot.new(http_user_agent)
      else
        Agent.new(http_user_agent)
      end
    end

    def self.to_agent_s(http_user_agent)
      agent = self.to_agent http_user_agent
      "(%s, %s)" % [agent.name, agent.os]
    end

    # this ensures the below module methods actually make sense...
    raise "Class #{base.name} should implement instance method 'http_user_agent'" unless base.instance_methods.include? 'http_user_agent'
    
  end
end

Instance Method Details

#search_bot?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/ntail/http_user_agent.rb', line 107

def search_bot?
  self.class.search_bot?(self.http_user_agent)
end

#to_agentObject



111
112
113
# File 'lib/ntail/http_user_agent.rb', line 111

def to_agent
  self.class.to_agent(self.http_user_agent)
end

#to_agent_sObject



115
116
117
# File 'lib/ntail/http_user_agent.rb', line 115

def to_agent_s
  self.class.to_agent_s(self.http_user_agent)
end