Sha256: 4c88ceca0230a0c4cf7da9dcf4bd6e2c43aa58e156315afacc9974f4607560f7
Contents?: true
Size: 1.82 KB
Versions: 2
Compression:
Stored size: 1.82 KB
Contents
# frozen_string_literal: true require_dependency "mr_common/application_record" module MrCommon class Reminder < ApplicationRecord validates :start_time, presence: true validates :end_time, presence: true validates :location, presence: true validates :summary, presence: true validates :slug, presence: true, uniqueness: true validates :start_time, presence: true validates :all_day, inclusion: [true, false] validates :time_zone, presence: true, inclusion: MrCommon::Timezone.time_zone_options, if: -> { time_zone.present? } before_validation :parameterize_slug def to_ical cal = Icalendar::Calendar.new cal.add_timezone(TZInfo::Timezone.get(time_zone).ical_timezone(start_time)) cal.event do |e| e.dtstart = calendar_start_time e.dtend = calendar_end_time e.summary = summary e.location = location e.description = description end cal.publish cal.to_ical end private def parameterize_slug self.slug = slug.parameterize.gsub(/(\W|_)/, "-") end def calendar_time_zone time_zone || "Etc/UTC" end def calendar_start_time if all_day? Icalendar::Values::DateOrDateTime.new(start_date_string, tzid: calendar_time_zone).call else Icalendar::Values::DateOrDateTime.new(start_time, tzid: calendar_time_zone) end end def calendar_end_time if all_day? Icalendar::Values::DateOrDateTime.new(end_date_string, tzid: calendar_time_zone).call else Icalendar::Values::DateOrDateTime.new(end_time, tzid: calendar_time_zone) end end def start_date_string start_time.strftime("%Y%m%d") end def end_date_string end_time.strftime("%Y%m%d") end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mr_common-1.3.0 | app/models/mr_common/reminder.rb |
mr_common-1.2.0 | app/models/mr_common/reminder.rb |