Class: UrlHelper
- Inherits:
-
Object
- Object
- UrlHelper
- Defined in:
- lib/url_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(domain, url) ⇒ UrlHelper
constructor
A new instance of UrlHelper.
- #url ⇒ Object
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
#url ⇒ Object
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 |