Class: MetaInspector::URL
- Inherits:
-
Object
- Object
- MetaInspector::URL
- Includes:
- Exceptionable
- Defined in:
- lib/meta_inspector/url.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
-
.absolutify(url, base_url) ⇒ Object
Converts a relative URL to an absolute URL, like: “/faq” => “example.com/faq” Respecting already absolute URLs like the ones starting with http:, ftp:, telnet:, mailto:, javascript: …
-
.unrelativize(url, scheme) ⇒ Object
Converts a protocol-relative url to its full form, depending on the scheme of the page that contains it.
Instance Method Summary collapse
- #host ⇒ Object
-
#initialize(initial_url, options = {}) ⇒ URL
constructor
A new instance of URL.
- #root_url ⇒ Object
- #scheme ⇒ Object
Constructor Details
#initialize(initial_url, options = {}) ⇒ URL
9 10 11 12 13 14 15 16 |
# File 'lib/meta_inspector/url.rb', line 9 def initialize(initial_url, = {}) = defaults.merge() @exception_log = [:exception_log] @normalize = [:normalize] self.url = initial_url end |
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/meta_inspector/url.rb', line 5 def url @url end |
Class Method Details
.absolutify(url, base_url) ⇒ Object
Converts a relative URL to an absolute URL, like:
"/faq" => "http://example.com/faq"
Respecting already absolute URLs like the ones starting with
http:, ftp:, telnet:, mailto:, javascript: ...
45 46 47 48 49 50 51 52 53 |
# File 'lib/meta_inspector/url.rb', line 45 def self.absolutify(url, base_url) if url =~ /^\w*\:/i MetaInspector::URL.new(url).url else Addressable::URI.join(base_url, url).normalize.to_s end rescue Addressable::URI::InvalidURIError nil end |
.unrelativize(url, scheme) ⇒ Object
Converts a protocol-relative url to its full form, depending on the scheme of the page that contains it
37 38 39 |
# File 'lib/meta_inspector/url.rb', line 37 def self.unrelativize(url, scheme) url =~ /^\/\// ? "#{scheme}://#{url[2..-1]}" : url end |
Instance Method Details
#host ⇒ Object
22 23 24 |
# File 'lib/meta_inspector/url.rb', line 22 def host parsed(url) ? parsed(url).host : nil end |
#root_url ⇒ Object
26 27 28 |
# File 'lib/meta_inspector/url.rb', line 26 def root_url "#{scheme}://#{host}/" end |
#scheme ⇒ Object
18 19 20 |
# File 'lib/meta_inspector/url.rb', line 18 def scheme parsed(url) ? parsed(url).scheme : nil end |