Sha256: d46ceeedd1f11005e209d55eb1856e40e47b7449876c996113ab1c96b3f60f6f
Contents?: true
Size: 1.42 KB
Versions: 4
Compression:
Stored size: 1.42 KB
Contents
module Schedular class Event < ActiveRecord::Base set_table_name :schedular_events has_and_belongs_to_many :times, :join_table => :schedular_events_times, :class_name => 'Schedular::Time'#, :order => 'value asc' validates_presence_of :name, :dates validate :times_not_empty named_scope :all, {} named_scope :include_times, :include => :times named_scope :by_time_or_period, lambda{ |time| time = Range === time || DateTime === time ? time : (time..time+1) {:conditions => {'schedular_times.value' => time}, :include => :times } } def dates= dates parsed = Eventual.parse dates, :lang => I18n.locale self.times = parsed.map do |time| # TODO: This method is soooo uneficient all_day = !(DateTime === time) Schedular::Time.all_day(all_day).by_time_or_period(time).first || Schedular::Time.new(:value => time, :all_day => all_day) end if parsed self['dates'] = dates end def self.by_params params return all unless params[:year] and params[:month] #TODO: Find by year day = Date.civil params[:year].to_i, params[:month].to_i, (params[:day] || 1).to_i params[:day] ? by_time_or_period(day) : by_time_or_period(day..day >> 1) end private def times_not_empty errors.add(:dates, I18n.t('activerecord.errors.messages.invalid')) if self.dates and self.times.empty? end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
schedular-0.1.4 | lib/schedular/event.rb |
schedular-0.1.3 | lib/schedular/event.rb |
schedular-0.1.2 | lib/schedular/event.rb |
schedular-0.1.1 | lib/schedular/event.rb |