Class: Elsmore::Url
- Inherits:
-
Object
- Object
- Elsmore::Url
- Defined in:
- lib/elsmore/url.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#raw_url ⇒ Object
Returns the value of attribute raw_url.
-
#uri ⇒ Object
Returns the value of attribute uri.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #absolute_path_or_external_url ⇒ Object
- #canonical_url ⇒ Object
- #host ⇒ Object
-
#initialize(raw_url, parent) ⇒ Url
constructor
A new instance of Url.
- #parent_host ⇒ Object
- #resource_path ⇒ Object
- #scheme ⇒ Object
Constructor Details
#initialize(raw_url, parent) ⇒ Url
5 6 7 8 9 10 11 12 |
# File 'lib/elsmore/url.rb', line 5 def initialize raw_url, parent self.raw_url = raw_url.strip self.parent = parent self.valid = true sanitize_string parse_uri end |
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/elsmore/url.rb', line 3 def parent @parent end |
#raw_url ⇒ Object
Returns the value of attribute raw_url.
3 4 5 |
# File 'lib/elsmore/url.rb', line 3 def raw_url @raw_url end |
#uri ⇒ Object
Returns the value of attribute uri.
3 4 5 |
# File 'lib/elsmore/url.rb', line 3 def uri @uri end |
#valid ⇒ Object
Returns the value of attribute valid.
3 4 5 |
# File 'lib/elsmore/url.rb', line 3 def valid @valid end |
Instance Method Details
#absolute_path_or_external_url ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/elsmore/url.rb', line 31 def absolute_path_or_external_url if parent && parent.host == host uri.path else canonical_url end end |
#canonical_url ⇒ Object
27 28 29 |
# File 'lib/elsmore/url.rb', line 27 def canonical_url uri.to_s end |
#host ⇒ Object
14 15 16 |
# File 'lib/elsmore/url.rb', line 14 def host uri.host end |
#parent_host ⇒ Object
18 19 20 21 |
# File 'lib/elsmore/url.rb', line 18 def parent_host return unless parent parent.host end |
#resource_path ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/elsmore/url.rb', line 39 def resource_path if parent && parent.host == host uri.path else canonical_url.gsub('http:/', '').gsub('https:/', '') end end |
#scheme ⇒ Object
23 24 25 |
# File 'lib/elsmore/url.rb', line 23 def scheme uri.scheme end |