class SmartURI::URI
Constants
- SEPARATOR
Public Class Methods
_expand(path, current, last)
click to toggle source
# File lib/smart_uri/uri.rb, line 25 def self._expand(path, current, last) if path.start_with?(SEPARATOR) && current != 0 path = path[1..-1] end unless path.end_with?(SEPARATOR) || current == last path = [path, SEPARATOR] end path end
join(*paths, query:{})
click to toggle source
# File lib/smart_uri/uri.rb, line 7 def self.join(*paths, query:{}) paths = paths.compact.reject(&:empty?) last = paths.length - 1 url = paths.each_with_index.map { |path, index| _expand(path, index, last) }.join result = if query.length > 0 url + "?#{::URI.encode_www_form(query.to_a)}" else url end new(result) end
new(val)
click to toggle source
# File lib/smart_uri/uri.rb, line 37 def initialize(val) @obj = (val.is_a?(::String) ? ::URI.parse(val) : val) end
parse(*args, **options)
click to toggle source
# File lib/smart_uri/uri.rb, line 21 def self.parse(*args, **options) join(*args, **options) end
Public Instance Methods
__getobj__()
click to toggle source
# File lib/smart_uri/uri.rb, line 41 def __getobj__ @obj end
join(*paths, **options)
click to toggle source
# File lib/smart_uri/uri.rb, line 45 def join(*paths, **options) self.class.join(*[self.to_s, paths].flatten, **options) end