Module: ActsAsWorkingDays::InstanceMethods

Defined in:
lib/acts_as_working_days.rb

Instance Method Summary collapse

Instance Method Details

#working_day?(params = {:week_day => Time.now.wday, :hour => Time.now.hour, :min => Time.now.min }) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/acts_as_working_days.rb', line 17

def working_day?(params ={:week_day => Time.now.wday, :hour => Time.now.hour, :min => Time.now.min })
  result = nil
  where = 'week_day = :week_day AND ((start_hour < :hour) OR (start_hour = :hour AND start_min <= :min)) AND ((end_hour > :hour) OR (end_hour = :hour AND end_min <= :min))'
  params = {:week_day => params[:week_day], :hour => params[:hour], :min => params[:min]}
  #To prevent @Depecrate
  if working_days.respond_to?('where')
    #Rails 3 style
    result = working_days.where(where, params)
  else
    #Rails 2x style
    result = working_days.find(:all, :conditions => [where, params])
  end
  return !result.empty?
end

#working_days_defaultsObject



32
33
34
35
36
37
38
# File 'lib/acts_as_working_days.rb', line 32

def working_days_defaults
  defaults = []
  7.times do | wday |
    defaults << (working_days.find_by_week_day(wday, :order => 'week_day ASC') || WorkingDay.new(:week_day => wday))
  end
  return defaults
end