class Typhoid::Uri

Attributes

base[RW]
paths[RW]

Public Class Methods

new(*paths) click to toggle source
# 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

Public Instance Methods

join(*more_paths) click to toggle source
# 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_s() click to toggle source
# File lib/typhoid/uri.rb, line 24
def to_s
  join
end

Private Instance Methods

sanitize(*need_sanitizing) click to toggle source
# File lib/typhoid/uri.rb, line 28
def sanitize(*need_sanitizing)
  need_sanitizing.
    flatten.
    compact.
    map { |p| p.to_s.split("/").compact.delete_if(&:empty?) }.
    flatten
end