Class: Anaximander::Url
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Anaximander::Url
- Includes:
- Comparable
- Defined in:
- lib/anaximander/url.rb
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #absolute(base) ⇒ Object
- #base ⇒ Object
- #eql?(other) ⇒ Boolean
-
#initialize(uri) ⇒ Url
constructor
A new instance of Url.
- #join(url) ⇒ Object
- #without_fragment ⇒ Object
Constructor Details
#initialize(uri) ⇒ Url
Returns a new instance of Url.
7 8 9 10 |
# File 'lib/anaximander/url.rb', line 7 def initialize(uri) @uri = URI(uri.to_s) super(@uri) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
5 6 7 |
# File 'lib/anaximander/url.rb', line 5 def uri @uri end |
Instance Method Details
#<=>(other) ⇒ Object
30 31 32 |
# File 'lib/anaximander/url.rb', line 30 def <=>(other) other.respond_to?(:uri) ? self.uri <=> other.uri : self.uri.to_s <=> other end |
#absolute(base) ⇒ Object
22 23 24 |
# File 'lib/anaximander/url.rb', line 22 def absolute(base) absolute? ? self : Url.new(base).join(self) end |
#base ⇒ Object
12 13 14 15 16 |
# File 'lib/anaximander/url.rb', line 12 def base domain = "#{scheme}://#{host}" domain += ":#{port}" unless port == 80 domain end |
#eql?(other) ⇒ Boolean
34 35 36 |
# File 'lib/anaximander/url.rb', line 34 def eql?(other) self.uri.eql?(other.uri) end |
#join(url) ⇒ Object
18 19 20 |
# File 'lib/anaximander/url.rb', line 18 def join(url) self.class.new(URI.join(self.uri, url.to_s)) end |
#without_fragment ⇒ Object
26 27 28 |
# File 'lib/anaximander/url.rb', line 26 def without_fragment self.class.new(self).tap { |url| url.fragment = nil } end |