class StubRequests::URI::Validator

Validator provides functionality for validating a {::URI}

Attributes

host[R]

@!attribute [r] host

@return [String] the URI host
scheme[R]

@!attribute [r] scheme

@return [String] the URI scheme
uri[R]

@!attribute [r] uri

@return [String] a complete URI

Public Class Methods

new(uri) click to toggle source

Initialize a new instance of {Validator}

@raise [InvalidUri] when URI can't be parsed

@param [String] uri the full URI

# File lib/stub_requests/uri/validator.rb, line 52
def initialize(uri)
  @uri    = ::URI.parse(uri)
  @host   = @uri.host
  @scheme = @uri.scheme
rescue ::URI::InvalidURIError
  raise InvalidUri, uri
end
valid?(uri) click to toggle source

Validates a URI

@param [String] uri a full uri with path

@return [true, false]

# File lib/stub_requests/uri/validator.rb, line 27
def self.valid?(uri)
  new(uri).valid?
end

Public Instance Methods

valid?() click to toggle source

Checks if a URI is valid

@return [true,false] <description>

# File lib/stub_requests/uri/validator.rb, line 66
def valid?
  URI::Scheme.valid?(scheme) && URI::Suffix.valid?(host)
end