Class: HashCast::Casters::DateCaster
- Inherits:
-
Object
- Object
- HashCast::Casters::DateCaster
- Defined in:
- lib/hash_cast/casters/date_caster.rb
Class Method Summary collapse
Class Method Details
.cast(value, attr_name, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/hash_cast/casters/date_caster.rb', line 5 def self.cast(value, attr_name, = {}) if value.is_a?(Date) value elsif value.is_a?(String) begin Date.parse(value) rescue ArgumentError => e raise HashCast::Errors::CastingError, "is invalid date" end else raise HashCast::Errors::CastingError, "should be a date" end end |