# frozen_string_literal: true

module OpenFoodNetwork
  class RefererParser
    def self.path(referer)
      parse_uri(referer)&.path if referer
    end

    def self.parse_uri(string)
      # TODO: make this operation obsolete by fixing URLs generated by AngularJS
      string.sub!('##', '#')
      URI(string)
    rescue URI::InvalidURIError
      nil
    end
  end
end
