Class: RVC::URIParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rvc/uri_parser.rb

Constant Summary collapse

URI_REGEX =

XXX comments TODO certdigest

%r{
  ^
  (?:
   (\w+):// # scheme
  )?
  (?:
    ([^@:]+) # username
    (?::
      ([^@]*) # password
    )?
    @
  )?
  ([^@:]+) # host
  (?::(\d{1,5}))? # port
  $
}x

Class Method Summary collapse

Class Method Details

.parse(str) ⇒ Object

Loosely parse a URI. This is more forgiving than a standard URI parser.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rvc/uri_parser.rb', line 45

def self.parse str
  match = URI_REGEX.match str
  Util.err "invalid URI" unless match

  URI::Generic.build({}).tap do |uri|
    uri.scheme = match[1] if match[1]
    uri.user = match[2] if match[2]
    uri.password = match[3] if match[3]
    uri.host = match[4] if match[4]
    uri.port = match[5].to_i if match[5]
  end
end