Class: URLWithRef

Inherits:
Object
  • Object
show all
Defined in:
lib/url_with_ref.rb

Instance Method Summary collapse

Constructor Details

#initialize(url, ref) ⇒ URLWithRef

Returns a new instance of URLWithRef.



6
7
8
9
# File 'lib/url_with_ref.rb', line 6

def initialize(url, ref)
  @url = url
  @ref = ref
end

Instance Method Details

#to_sObject



11
12
13
14
15
16
17
18
19
# File 'lib/url_with_ref.rb', line 11

def to_s
  uri = URI(@url&.strip).normalize
  params = URI.decode_www_form(uri.query || "")
  params << ["ref", @ref] unless params.any? { |param| param.index "ref" }
  uri.query = URI.encode_www_form(params)
  uri.to_s
rescue StandardError => e
  @url
end