Class: Elsmore::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/elsmore/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/elsmore/url.rb', line 3

def parent
  @parent
end

#raw_urlObject

Returns the value of attribute raw_url.



3
4
5
# File 'lib/elsmore/url.rb', line 3

def raw_url
  @raw_url
end

#uriObject

Returns the value of attribute uri.



3
4
5
# File 'lib/elsmore/url.rb', line 3

def uri
  @uri
end

#validObject

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_urlObject



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_urlObject



27
28
29
# File 'lib/elsmore/url.rb', line 27

def canonical_url
  uri.to_s
end

#hostObject



14
15
16
# File 'lib/elsmore/url.rb', line 14

def host
  uri.host
end

#parent_hostObject



18
19
20
21
# File 'lib/elsmore/url.rb', line 18

def parent_host
  return unless parent
  parent.host
end

#resource_pathObject



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

#schemeObject



23
24
25
# File 'lib/elsmore/url.rb', line 23

def scheme
  uri.scheme
end