Class: Timeoff

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/timeoff.rb

Overview

Schema Information

Table name: timeoffs

id :integer not null, primary key day_of_week :integer reason :string(255) all_day :boolean default(FALSE) start_time :time end_time :time status :string(255) default("pending") user_id :integer created_at :datetime updated_at :datetime off_date :date approved_date :datetime approved_by :integer cancelled_date :datetime vacation :boolean default(FALSE)

Instance Method Summary collapse

Instance Method Details

#all_day_absence? ⇒ Boolean

before_save :create_vacation_info

Returns:

  • (Boolean)


32
33
34
# File 'app/models/timeoff.rb', line 32

def all_day_absence?
  self.all_day == true
end

#approve(manager) ⇒ Object



58
59
60
61
62
63
64
# File 'app/models/timeoff.rb', line 58

def approve(manager)
  create_vacation_info
  self.approved_by = manager.id
  self.approved_date = DateTime.now
  self.status = 'approved'
  save
end

#approved? ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/timeoff.rb', line 36

def approved?
  self.status == 'approved'
end

#cancel ⇒ Object



66
67
68
69
70
# File 'app/models/timeoff.rb', line 66

def cancel
  self.status = 'cancelled'
  self.cancelled_date = DateTime.now
  save
end

#detail ⇒ Object



50
51
52
# File 'app/models/timeoff.rb', line 50

def detail
  return "Your TimeOff Request for #{off_date} has been approved"
end

#formatted_due_date ⇒ Object



54
55
56
# File 'app/models/timeoff.rb', line 54

def formatted_due_date
  "#{off_date.strftime('%A')},#{off_date.strftime('%B')} #{off_date.day}, #{off_date.year}"
end

#interfere?(start_time, end_time) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
# File 'app/models/timeoff.rb', line 40

def interfere?(start_time, end_time)
  if ( self.start_time < start_time && self.end_time > start_time ) ||
      ( end_time > self.start_time && end_time < self.end_time ) ||
      ( self.start_time > start_time && self.end_time < end_time )
    true
  else
    false
  end
end