Class: WorkScheduleDay

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/work_schedule_day.rb

Overview

== Schema Information

Table name: work_schedule_days
Database name: primary

id :bigint not null, primary key
day_of_week :integer not null
end_time :time not null
hours :float not null
lunch_end_time :time
lunch_start_time :time
notes :text
start_time :time not null
created_at :datetime not null
updated_at :datetime not null
work_schedule_id :bigint not null

Indexes

index_work_schedule_days_on_day_of_week (day_of_week)
index_work_schedule_days_on_work_schedule_id_and_day_of_week (work_schedule_id,day_of_week) UNIQUE

Foreign Keys

fk_rails_... (work_schedule_id => work_schedules.id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Constants included from Models::Schedulable

Models::Schedulable::SIMPLE_FORM_OPTIONS

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Instance Method Summary collapse

Methods included from Models::Auditable

#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::Schedulable

config

Methods included from Models::AfterCommittable

#after_commit

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#day_of_weekInteger (readonly)

Returns:

  • (Integer)


34
# File 'app/models/work_schedule_day.rb', line 34

validates :day_of_week, presence: true

#end_timeTime (readonly)

Returns:

  • (Time)


38
# File 'app/models/work_schedule_day.rb', line 38

validates :end_time, presence: true

#hoursFloat (readonly)

Returns:

  • (Float)


40
# File 'app/models/work_schedule_day.rb', line 40

validates :hours, presence: true

#start_timeTime (readonly)

Returns:

  • (Time)


36
# File 'app/models/work_schedule_day.rb', line 36

validates :start_time, presence: true

Instance Method Details

#day_namevoid

This method returns an undefined value.



43
44
45
# File 'app/models/work_schedule_day.rb', line 43

def day_name
  Date::DAYNAMES[day_of_week]
end

#formatted_end_timevoid

This method returns an undefined value.



53
54
55
# File 'app/models/work_schedule_day.rb', line 53

def formatted_end_time
  end_time&.strftime('%H:%M')
end

#formatted_lunch_timesvoid

This method returns an undefined value.



58
59
60
61
62
# File 'app/models/work_schedule_day.rb', line 58

def formatted_lunch_times
  return nil unless lunch_start_time && lunch_end_time

  "#{lunch_start_time.strftime('%H:%M')} - #{lunch_end_time.strftime('%H:%M')}"
end

#formatted_start_timevoid

This method returns an undefined value.



48
49
50
# File 'app/models/work_schedule_day.rb', line 48

def formatted_start_time
  start_time&.strftime('%H:%M')
end

#time_off_request_day_payloadObject

Snapshot for time-off requests (hour-based partial days): usual weekly pattern for this weekday.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/models/work_schedule_day.rb', line 65

def time_off_request_day_payload
  {
    day_of_week: day_of_week,
    day_name: day_name,
    start_time: formatted_start_time,
    end_time: formatted_end_time,
    lunch_start: lunch_start_time&.strftime('%H:%M'),
    lunch_end: lunch_end_time&.strftime('%H:%M'),
    lunch_label: formatted_lunch_times,
    hours: hours,
    summary: time_off_schedule_summary_line
  }
end

#time_off_schedule_summary_linevoid

This method returns an undefined value.



80
81
82
83
84
85
86
# File 'app/models/work_schedule_day.rb', line 80

def time_off_schedule_summary_line
  parts = []
  parts << "#{format_time_ampm(start_time)}#{format_time_ampm(end_time)}" if start_time && end_time
  parts << "Lunch #{format_time_ampm(lunch_start_time)} - #{format_time_ampm(lunch_end_time)}" if lunch_start_time && lunch_end_time
  parts << "#{hours} h" if hours.present?
  parts.join(' · ')
end

#work_scheduleWorkSchedule?

Returns:



31
# File 'app/models/work_schedule_day.rb', line 31

belongs_to :work_schedule