class Xcflushd::GLIHelpers::GenericURI

URI parsing for GLI

Constants

SCHEME_RE

tools.ietf.org/html/rfc3986#appendix-A

Public Class Methods

new(s, default_port = nil) click to toggle source
# File lib/xcflushd/gli_helpers.rb, line 38
def self.new(s, default_port = nil)
  # URI.parse won't correctly parse a URI without a scheme
  unless SCHEME_RE.match s
    s = "generic://#{s}"
  end
  uri = URI.parse(s)
  # exit with an error if no host parsed
  return false unless uri.host
  if !uri.port && default_port
    uri.port = default_port
  end
  uri.define_singleton_method :to_a do
    [self]
  end
  uri
end