Class: Schedular::Event

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/schedular/event.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_params(params) ⇒ Object



39
40
41
42
43
# File 'lib/schedular/event.rb', line 39

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

Instance Method Details

#dates=(dates) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/schedular/event.rb', line 16

def dates= dates
  parsed = Eventual.parse dates, :lang => I18n.locale
  
  if parsed
    self.times = parsed.map do |time|
      all_day  = time.class == Date
      
      if Range === time
        duration = ((time.last.to_f - time.first.to_f) / 60).to_i
        time     = time.first
      else
        duration = nil
      end
      # TODO: This method is soooo uneficient
      Schedular::Time.by_time_or_period(time).all_day(all_day).duration(duration).first || Schedular::Time.new(:value => time, :all_day => all_day, :duration => duration)
    end
  else
    self.times = []
  end
  
  self['dates'] = dates
end