Sha256: 3df05fe75fb742e4a7f66961730713c596a07bd066a24ca62a652bc3d6e83cad

Contents?: true

Size: 776 Bytes

Versions: 9

Compression:

Stored size: 776 Bytes

Contents

module SmsAero::Types
  # Describes a user's birthday in year-month-date format
  # Accepts dates, times, datetimes, and strings parceable to dates
  #
  # @example
  #   SmsAero::Types::Birthday["1901-12-9"]                   # => "1901-12-09"
  #   SmsAero::Types::Birthday[Time.new(1901, 12, 9, 10, 12)] # => "1901-12-09"
  #
  Birthday = Strict::String
             .constrained(format: /\A\d{4}-\d{2}-\d{2}\z/)
             .constructor do |value|
               begin
                 date = value.to_date if value.respond_to? :to_date
                 date ||= ::Date.parse(value.to_s)
                 date.strftime "%Y-%m-%d"
               rescue
                 raise TypeError, "#{value.inspect} cannot be coerced to date"
               end
             end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sms_aero-0.0.9 lib/sms_aero/types/birthday.rb
sms_aero-0.0.8 lib/sms_aero/types/birthday.rb
sms_aero-0.0.7 lib/sms_aero/types/birthday.rb
sms_aero-0.0.6 lib/sms_aero/types/birthday.rb
sms_aero-0.0.5 lib/sms_aero/types/birthday.rb
sms_aero-0.0.4 lib/sms_aero/types/birthday.rb
sms_aero-0.0.3 lib/sms_aero/types/birthday.rb
sms_aero-0.0.2 lib/sms_aero/types/birthday.rb
sms_aero-0.0.1 lib/sms_aero/types/birthday.rb