Class: UrlHelper

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, url) ⇒ UrlHelper

Returns a new instance of UrlHelper.



10
11
12
13
# File 'lib/url_helper.rb', line 10

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

Class Method Details

.url_for(domain, url) ⇒ Object



4
5
6
# File 'lib/url_helper.rb', line 4

def self.url_for(domain, url)
  new(domain, url).url
end

Instance Method Details

#urlObject



15
16
17
18
19
20
21
22
# File 'lib/url_helper.rb', line 15

def url
  return if @url.nil?

  parsed = Addressable::URI.parse(@url)
  full_url = valid?(parsed) ? parsed.to_s : domain_uri
  Addressable::URI.escape(full_url)
rescue Addressable::URI::InvalidURIError
end