Class: Highway::Steps::Types::String
- Defined in:
- lib/highway/steps/types/string.rb
Overview
This class represents a string parameter type.
Class Method Summary collapse
-
.regex(regex) ⇒ Highway::Steps::Types::String
Initialize an instance.
Instance Method Summary collapse
-
#typecheck(value) ⇒ String?
Typecheck and coerce a value if possible.
Methods inherited from Any
#initialize, #typecheck_and_validate, #validate
Constructor Details
This class inherits a constructor from Highway::Steps::Types::Any
Class Method Details
permalink .regex(regex) ⇒ Highway::Steps::Types::String
Initialize an instance.
22 23 24 |
# File 'lib/highway/steps/types/string.rb', line 22 def self.regex(regex) self.new(validate: lambda { |value| regex =~ value }) end |
Instance Method Details
permalink #typecheck(value) ⇒ String?
Typecheck and coerce a value if possible.
This method returns a typechecked and coerced value or ‘nil` if value has invalid type and can’t be coerced.
34 35 36 37 38 39 40 41 |
# File 'lib/highway/steps/types/string.rb', line 34 def typecheck(value) case value when ::String then value when ::Numeric then value.to_s when ::TrueClass then "true" when ::FalseClass then "false" end end |