Class: DateValues::Rails::MonthDayType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/date_values/rails/month_day_type.rb

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/date_values/rails/month_day_type.rb', line 10

def cast(value)
  case value
  when MonthDay then value
  when Hash     then cast_hash(value)
  when String   then MonthDay.parse(value)
  when nil      then nil
  end
rescue ArgumentError
  nil
end

#deserialize(value) ⇒ Object



25
26
27
28
29
# File 'lib/date_values/rails/month_day_type.rb', line 25

def deserialize(value)
  return nil if value.nil?

  MonthDay.parse(value)
end

#serialize(value) ⇒ Object



21
22
23
# File 'lib/date_values/rails/month_day_type.rb', line 21

def serialize(value)
  value&.to_s
end

#typeObject



6
7
8
# File 'lib/date_values/rails/month_day_type.rb', line 6

def type
  :month_day
end