Sha256: bdb8d7e693b5ea88dc342c94023355dba28122b5fa7b9bcb410cc8b03e5c3985

Contents?: true

Size: 770 Bytes

Versions: 6

Compression:

Stored size: 770 Bytes

Contents

# frozen_string_literal: true

module CrawlerDetect
  # @since 0.1.0
  module Library
    DATA_CLASSES = [Library::Headers, Library::Exclusions, Library::Crawlers].freeze

    @regexp_cache = {}

    class << self
      # @param param [String] Name of raw data
      # @return [Regexp]
      def get_regexp(param)
        @regexp_cache[param] ||= begin
          data = get_array(param)
          %r{#{data.join('|')}}i
        end
      end

      # @param param [String] Name of raw data
      # @return [Array]
      def get_array(param)
        const_get("CrawlerDetect::Library::#{param.capitalize}").send(:data)
      end

      # @return [void]
      def reset_cache
        DATA_CLASSES.each(&:reload_data)
        @regexp_cache = {}
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
crawler_detect-1.2.5 lib/crawler_detect/library.rb
crawler_detect-1.2.4 lib/crawler_detect/library.rb
crawler_detect-1.2.3 lib/crawler_detect/library.rb
crawler_detect-1.2.2 lib/crawler_detect/library.rb
crawler_detect-1.2.1 lib/crawler_detect/library.rb
crawler_detect-1.2.0 lib/crawler_detect/library.rb