Class: Sinatra::Browse::ParameterTypes::DateTime
- Inherits:
-
Sinatra::Browse::ParameterType
- Object
- Sinatra::Browse::ParameterType
- Sinatra::Browse::ParameterTypes::DateTime
- Extended by:
- MinMax
- Defined in:
- lib/sinatra/browse/parameter_types/date_time.rb
Instance Attribute Summary
Attributes inherited from Sinatra::Browse::ParameterType
#default, #description, #name, #validators
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(name, map) ⇒ DateTime
constructor
A new instance of DateTime.
Methods included from MinMax
Methods inherited from Sinatra::Browse::ParameterType
#build_error_hash, #default_set?, inherited, #required?, #to_hash, #transform, #type, #validate, validator, validator_declarations, #validator_declarations
Constructor Details
#initialize(name, map) ⇒ DateTime
Returns a new instance of DateTime.
11 12 13 14 15 16 17 |
# File 'lib/sinatra/browse/parameter_types/date_time.rb', line 11 def initialize(name, map) # Allow strings for min and max values map[:min] = coerce(map[:min]) if map[:min].is_a?(::String) map[:max] = coerce(map[:max]) if map[:max].is_a?(::String) super(name, map) end |
Instance Method Details
#coerce(value) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/sinatra/browse/parameter_types/date_time.rb', line 19 def coerce(value) # We add this line because default values also get coerced. return value if value.is_a?(::DateTime) ::DateTime.parse(value) end |