Sha256: 1af93d71298a4da81bae81e12fd4c5ace17557abdf97f653ae6a220b64d9b3b0

Contents?: true

Size: 844 Bytes

Versions: 2

Compression:

Stored size: 844 Bytes

Contents

require 'irus_analytics'
require 'singleton'

module IrusAnalytics
  class UserAgentFilter
    include Singleton

    # Singleton module defines us a instance class method and makes this private...
    def initialize
      set_robot_agents
    end

    def filter_user_agent?(user_agent)
      @robot_agents.each do |robot_regexp|
        return true unless user_agent.match(robot_regexp).nil? 
      end
      return false
    end

    def set_robot_agents
      @robot_agents = get_robots_from_config
    end
  
    private

    def get_robots_from_config
      begin 
        agent_list = File.open("#{IrusAnalytics.config}/counter_robot_list.txt", "r") { |config| config.readlines.collect{|line| line.chomp }}
      rescue Exception => ex
          # Deal with configuration read error
          agent_list = []
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
irus_analytics-0.0.2 lib/irus_analytics/user_agent_filter.rb
irus_analytics-0.0.1 lib/irus_analytics/user_agent_filter.rb