Sha256: 8490d69d74c90ba656dd0f1f01d516b389a0431375e434ea8bdf2263454f4bf2

Contents?: true

Size: 787 Bytes

Versions: 5

Compression:

Stored size: 787 Bytes

Contents

class Browser
  module Bots
    root = Pathname.new(File.expand_path("../../../..", __FILE__))
    BOTS = YAML.load_file(root.join("bots.yml"))
    SEARCH_ENGINES = YAML.load_file(root.join("search_engines.yml"))

    def self.detect_empty_ua!
      @detect_empty_ua = true
    end

    def self.detect_empty_ua?
      !!@detect_empty_ua
    end

    def bot?
      bot_with_empty_ua? || BOTS.any? {|key, _| ua.include?(key) }
    end

    def bot_name
      return unless bot?
      return "Generic Bot" if bot_with_empty_ua?
      BOTS.find {|key, _| ua.include?(key) }.first
    end

    def search_engine?
      SEARCH_ENGINES.any? {|key, _| ua.include?(key) }
    end

    private

    def bot_with_empty_ua?
      Browser::Bots.detect_empty_ua? && ua.strip == ""
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
browser-1.1.0 lib/browser/methods/bots.rb
browser-1.0.1 lib/browser/methods/bots.rb
browser-1.0.0 lib/browser/methods/bots.rb
browser-0.9.1 lib/browser/methods/bots.rb
browser-0.9.0 lib/browser/methods/bots.rb