Class: Typhoid::Uri

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoid/uri.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*paths) ⇒ Uri

Returns a new instance of Uri.



12
13
14
15
16
17
# File 'lib/typhoid/uri.rb', line 12

def initialize(*paths)
  self.base = URI.parse paths.shift.to_s
  self.paths = sanitize(base.path) + sanitize(paths)
  base.path = ""
  raise "Invalid Base on #uri_join: #{base}" unless base.scheme || base.host
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



9
10
11
# File 'lib/typhoid/uri.rb', line 9

def base
  @base
end

#pathsObject

Returns the value of attribute paths.



10
11
12
# File 'lib/typhoid/uri.rb', line 10

def paths
  @paths
end

Instance Method Details

#join(*more_paths) ⇒ Object



19
20
21
22
# File 'lib/typhoid/uri.rb', line 19

def join(*more_paths)
  full_path = (paths + sanitize(more_paths)).join "/"
  base.clone.merge(full_path).to_s
end

#to_sObject



24
25
26
# File 'lib/typhoid/uri.rb', line 24

def to_s
  join
end