class UrlHelper
Public Class Methods
new(domain, url)
click to toggle source
# File lib/url_helper.rb, line 10 def initialize(domain, url) @domain = domain @url = url end
url_for(domain, url)
click to toggle source
# File lib/url_helper.rb, line 4 def self.url_for(domain, url) new(domain, url).url end
Public Instance Methods
url()
click to toggle source
# 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
Private Instance Methods
domain_uri()
click to toggle source
# File lib/url_helper.rb, line 30 def domain_uri domain = Addressable::URI.parse(@domain) domain.query = nil domain.path = if @url.start_with?('/') @url else domain.path + '/' + @url end domain.to_s end
valid?(parsed)
click to toggle source
# File lib/url_helper.rb, line 26 def valid?(parsed) parsed.host && (parsed.scheme || @url.start_with?('//')) end