module DateBook::ActsAsSchedule::InstanceMethods
Instance Methods
Public Instance Methods
duration_attributes()
click to toggle source
# File lib/date_book/concerns/acts_as_schedule.rb, line 12 def duration_attributes OpenStruct.new count: duration_count, unit: duration_unit end
duration_attributes=(value)
click to toggle source
Calls superclass method
# File lib/date_book/concerns/acts_as_schedule.rb, line 16 def duration_attributes=(value) if value.is_a? Hash self.duration = value['count'].to_i.send(value['unit'].to_sym).to_i end super value end
duration_count()
click to toggle source
# File lib/date_book/concerns/acts_as_schedule.rb, line 23 def duration_count duration / 1.send(duration_unit.singularize.to_sym).to_i end
duration_unit()
click to toggle source
# File lib/date_book/concerns/acts_as_schedule.rb, line 27 def duration_unit return 'seconds' if duration.zero? DateBook .configuration .duration_units .select { |x| unit_matches? x } .first || 'seconds' end
human_date()
click to toggle source
# File lib/date_book/concerns/acts_as_schedule.rb, line 36 def human_date I18n.localize date, format: :human_date end
human_time()
click to toggle source
# File lib/date_book/concerns/acts_as_schedule.rb, line 40 def human_time I18n.localize time, format: :human_time end
Private Instance Methods
unit_matches?(unit)
click to toggle source
# File lib/date_book/concerns/acts_as_schedule.rb, line 46 def unit_matches?(unit) (duration % 1.send(unit.singularize.to_sym).to_i).zero? end