Class: Magiq::Types::Date

Inherits:
Type
  • Object
show all
Defined in:
lib/magiq/types.rb

Constant Summary collapse

DATE_RNG =
/[12]{1}[0-9]{3}\-[10]{1}[0-9]{1}\-[0123]{1}[0-9]{1}/

Instance Attribute Summary

Attributes inherited from Type

#raw

Instance Method Summary collapse

Methods inherited from Type

cast, #initialize

Constructor Details

This class inherits a constructor from Magiq::Types::Type

Instance Method Details

#cast!Object



205
206
207
208
209
210
211
212
# File 'lib/magiq/types.rb', line 205

def cast!
  if raw =~ DATE_RNG
    Date.parse($1)
  else
    bad! "provided value of #{raw.inspect} is not permitted, it must " \
    "be an ISO 8601 formatted date: YYYY-MM-DD"
  end
end