Class: StubRequests::URI::Validator
- Defined in:
- lib/stub_requests/uri/validator.rb
Overview
Validator provides functionality for validating a URI
Instance Attribute Summary collapse
- #host ⇒ Object readonly
- #scheme ⇒ Object readonly
- #uri ⇒ Object readonly
Class Method Summary collapse
-
.valid?(uri) ⇒ true, false
Validates a URI.
Instance Method Summary collapse
-
#initialize(uri) ⇒ Validator
constructor
Initialize a new instance of Validator.
-
#valid? ⇒ true, false
Checks if a URI is valid.
Constructor Details
#initialize(uri) ⇒ Validator
Initialize a new instance of StubRequests::URI::Validator
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
#host ⇒ Object (readonly)
38 39 40 |
# File 'lib/stub_requests/uri/validator.rb', line 38 def host @host end |
#scheme ⇒ Object (readonly)
42 43 44 |
# File 'lib/stub_requests/uri/validator.rb', line 42 def scheme @scheme end |
#uri ⇒ Object (readonly)
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
27 28 29 |
# File 'lib/stub_requests/uri/validator.rb', line 27 def self.valid?(uri) new(uri).valid? end |