Class: HhPackage::Agenda Private
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HhPackage::Agenda
- Includes:
- IdentityCache
- Defined in:
- app/models/hh_package/agenda.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Model for save timetable or schedule data to database
Defined Under Namespace
Classes: InvalidSchedule
Instance Attribute Summary collapse
- #skip_validation ⇒ Object private
Class Method Summary collapse
- .day_to_number(day_name) ⇒ Object private
- .days_attr_to_ice_cube(day_names) ⇒ Object private
- .days_attributes ⇒ Object private
Instance Method Summary collapse
- #all_day ⇒ Object private
- #all_day=(bool) ⇒ Object private
- #available_at?(start_date, end_date, time_zone, date_time) ⇒ Boolean private
- #available_times(start_date, end_date, time_zone, date) ⇒ Object private
- #schedule_obj(start_date, end_date, time_zone) ⇒ Object private
- #special? ⇒ Boolean private
- #to_ice_cube(start_date, end_date) ⇒ Object private
Methods inherited from ApplicationRecord
Instance Attribute Details
#skip_validation ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 |
# File 'app/models/hh_package/agenda.rb', line 44 def skip_validation @skip_validation end |
Class Method Details
.day_to_number(day_name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'app/models/hh_package/agenda.rb', line 392 def day_to_number(day_name) case day_name.to_s.downcase when 'sun', 'sunday' 0 when 'mon', 'monday' 1 when 'tue', 'tuesday' 2 when 'wed', 'wednesday' 3 when 'thu', 'thursday' 4 when 'fri', 'friday' 5 when 'sat', 'saturday' 6 else raise NotImplementedError end end |
.days_attr_to_ice_cube(day_names) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'app/models/hh_package/agenda.rb', line 413 def days_attr_to_ice_cube(day_names) day_names = day_names.select { |_day_name, value| value == true } day_names.map do |day_name, _| case day_name when 'sun', 'sunday' :sunday when 'mon', 'monday' :monday when 'tue', 'tuesday' :tuesday when 'wed', 'wednesday' :wednesday when 'thu', 'thursday' :thursday when 'fri', 'friday' :friday when 'sat', 'saturday' :saturday else raise NotImplementedError end end end |
.days_attributes ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
437 438 439 |
# File 'app/models/hh_package/agenda.rb', line 437 def days_attributes %w[sun mon tue wed thu fri sat] end |
Instance Method Details
#all_day ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 68 69 70 |
# File 'app/models/hh_package/agenda.rb', line 65 def all_day return false if end_time.blank? duration = end_time - start_time start_time == end_time || duration == 1.day || duration == 1.day - 1.minute end |
#all_day=(bool) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 75 76 77 |
# File 'app/models/hh_package/agenda.rb', line 72 def all_day=(bool) return unless bool self.start_time = '00:00' self.end_time = '23:59' end |
#available_at?(start_date, end_date, time_zone, date_time) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 80 81 |
# File 'app/models/hh_package/agenda.rb', line 79 def available_at?(start_date, end_date, time_zone, date_time) schedule_obj(start_date, end_date, time_zone)&.occurs_at?(date_time).presence || false end |
#available_times(start_date, end_date, time_zone, date) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/hh_package/agenda.rb', line 83 def available_times(start_date, end_date, time_zone, date) unless date.is_a?(Date) date = Time.use_zone(time_zone) do Time.zone.parse(date).to_date end end result = schedule_obj(start_date, end_date, time_zone)&.occurrences_between(date.beginning_of_day, date.end_of_day) result.presence || [] end |
#schedule_obj(start_date, end_date, time_zone) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/hh_package/agenda.rb', line 94 def schedule_obj(start_date, end_date, time_zone) ice_cube_obj = use_zone(time_zone) do to_ice_cube(start_date.to_date, end_date.to_date) end return nil if ice_cube_obj.nil? IceCube::Schedule.from_yaml ice_cube_obj rescue StandardError => e APMErrorHandler.report(e) nil end |
#special? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
106 107 108 |
# File 'app/models/hh_package/agenda.rb', line 106 def special? fetch_package.special_agenda? end |
#to_ice_cube(start_date, end_date) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/models/hh_package/agenda.rb', line 110 def to_ice_cube(start_date, end_date) return nil if special? && single_occurrences.blank? return nil if !special? && start_time.blank? st = if special? single = single_occurrences.min_by do |single_occurrence| Time.zone.parse("#{single_occurrence[:start_date].to_date} #{single_occurrence[:start_time]}") end if single[:all_day].to_s == 'true' Time.zone.parse("#{single[:start_date].to_date}}").beginning_of_day else return nil if single[:start_date].blank? || single[:start_time].blank? Time.zone.parse("#{single[:start_date].to_date} #{single[:start_time]}") end else return nil if start_date.nil? || start_time.blank? time = start_time.strftime('%H:%M') Time.zone.parse("#{start_date} #{time}") end sc = IceCube::Schedule.new st rules = if special? special_agenda_rules else regular_agenda_rules(st, end_date) end if special? rules.each do |rule| sc.rtime rule end else rules.each do |rule| sc.rrule rule end end unless special? now = Time.zone.now exception_occurrences.each do |exc| exc = exc.to_hash.with_indifferent_access all_day = exc[:all_day].to_s == 'true' start_time = Time.zone.parse("#{exc[:start_date].to_date} #{all_day ? '00:00' : exc[:start_time]}") end_time = Time.zone.parse("#{exc[:end_date].to_date} #{all_day ? '23:59' : determine_end_time(exc[:end_time]).strftime('%H:%M')}") next if end_time < now next if end_time <= start_time sc.occurrences_between(start_time, end_time).each do |occ_time| sc.add_exception_time(occ_time.to_time) end end end sc.to_yaml rescue StandardError => e Rails.logger.error e raise e end |