Class: Tod::TimeOfDayType

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/tod/time_of_day_type.rb

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/tod/time_of_day_type.rb', line 3

def cast(value)
  if value.is_a? Hash
      # rails multiparam attribute
      # get hour, minute and second and construct new TimeOfDay object
    ::Tod::TimeOfDay.new(value[4], value[5], value[6])
  else
    # return nil, if input is not parsable
    Tod::TimeOfDay(value){}
  end
end

#serialize(value) ⇒ Object



14
15
16
# File 'lib/tod/time_of_day_type.rb', line 14

def serialize(value)
  value.to_s if value.present?
end