Class: StubRequests::URI::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/stub_requests/uri/validator.rb

Overview

Validator provides functionality for validating a URI

Since:

  • 0.1.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Validator

Initialize a new instance of StubRequests::URI::Validator

Parameters:

  • uri (String)

    the full URI

Raises:

Since:

  • 0.1.0



52
53
54
55
56
57
58
# 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

Instance Attribute Details

#hostObject (readonly)

Since:

  • 0.1.0



38
39
40
# File 'lib/stub_requests/uri/validator.rb', line 38

def host
  @host
end

#schemeObject (readonly)

Since:

  • 0.1.0



42
43
44
# File 'lib/stub_requests/uri/validator.rb', line 42

def scheme
  @scheme
end

#uriObject (readonly)

Since:

  • 0.1.0



34
35
36
# File 'lib/stub_requests/uri/validator.rb', line 34

def uri
  @uri
end

Class Method Details

.valid?(uri) ⇒ true, false

Validates a URI

Parameters:

  • uri (String)

    a full uri with path

Returns:

  • (true, false)

Since:

  • 0.1.0



27
28
29
# File 'lib/stub_requests/uri/validator.rb', line 27

def self.valid?(uri)
  new(uri).valid?
end

Instance Method Details

#valid?true, false

Checks if a URI is valid

Returns:

  • (true, false)

Since:

  • 0.1.0



66
67
68
# File 'lib/stub_requests/uri/validator.rb', line 66

def valid?
  URI::Scheme.valid?(scheme) && URI::Suffix.valid?(host)
end