Sha256: 62c4ad3524f3fcf5222d1ae87aa696c54859a39db4a2ab5ca63dfcb87a173f59

Contents?: true

Size: 787 Bytes

Versions: 4

Compression:

Stored size: 787 Bytes

Contents

# encoding: utf-8

module UseragentParser
  class ReferrerParser
    attr_accessor :pattern, :referrer_re, :referrer_replacement

    def initialize(pattern, referrer_replacement = nil)
      @pattern = pattern
      @referrer_re = Regexp.compile(pattern)
      @referrer_replacement = referrer_replacement
    end

    def match_spans(referrer_string)
      match_spans = []
      match = @referrer_re.match(referrer_string)
      if match
        # Return the offsets
      end
    end

    def parse(referrer_string)
      referrer = nil
      match = @referrer_re.match(referrer_string)
      if match
        if @referrer_replacement
          referrer = @referrer_replacement
        else
          referrer = match[1]
        end
      end
      return referrer
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
useragent_parser-0.2.3 lib/useragent_parser/parsers/referrer_parser.rb
useragent_parser-0.2.2 lib/useragent_parser/parsers/referrer_parser.rb
useragent_parser-0.2.1 lib/useragent_parser/parsers/referrer_parser.rb
useragent_parser-0.2.0 lib/useragent_parser/parsers/referrer_parser.rb