class HTTPLogAnalyzer::Element::Referer

Constants

QueryKeys

Attributes

query[RW]
uri[RW]

Public Instance Methods

parse(string) click to toggle source
# File lib/http-log-analyzer/element/referer.rb, line 12
def parse(string)
  if string != '-'
    @uri = Addressable::URI.parse(string) or raise ParseError, "Can't parse URI: #{string}"
    normalize_uri!(@uri)
    if @uri.host
      # normalize Facebook link-shims
      if @uri.host =~ /^(l|lm)\.facebook\.com$/ || @uri.path.start_with?('/l.php')
        @uri.host = 'facebook.com'
        @uri.path = '/'
        @uri.query = nil
      end
      if (values = @uri.query_values)
        QueryKeys.each do |key|
          if (value = values[key]) && !value.empty?
            @query = values[key]
            break
          end
        end
      end
    end
  end
end