Class: Anaximander::Url

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Comparable
Defined in:
lib/anaximander/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#uriObject (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

#baseObject



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

Returns:

  • (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_fragmentObject



26
27
28
# File 'lib/anaximander/url.rb', line 26

def without_fragment
  self.class.new(self).tap { |url| url.fragment = nil }
end