Class: Parameters::Types::URI

Inherits:
Object show all
Defined in:
lib/parameters/types/uri.rb

Class Method Summary collapse

Methods inherited from Object

#===, to_ruby

Methods inherited from Type

#<, #<=, #==, #===, #coerce, #to_ruby, to_ruby

Class Method Details

.===(value) ⇒ Boolean

Determines if the value is already a URI.

Parameters:

  • value (Object)

    The value to inspect.

Returns:

  • (Boolean)

    Specifies whether the value inherits URI::Generic.



18
19
20
# File 'lib/parameters/types/uri.rb', line 18

def self.===(value)
  value.kind_of?(::URI::Generic)
end

.coerce(value) ⇒ URI::Generic

Coerces a value into a URI.

Parameters:

  • value (#to_uri, #to_s)

    The value to coerce.

Returns:

  • (URI::Generic)

    The coerced URI.



31
32
33
34
35
36
37
# File 'lib/parameters/types/uri.rb', line 31

def self.coerce(value)
  if value.respond_to?(:to_uri)
    value.to_uri
  else
    ::URI.parse(value.to_s)
  end
end