Class: Receptionist::GetEndTime
- Inherits:
-
Object
- Object
- Receptionist::GetEndTime
- Defined in:
- app/my_lib/receptionist/get_end_time.rb
Overview
This class can be used for determine end time of a reservation
Defined Under Namespace
Classes: InvalidRestaurant, InvalidSchedule
Instance Attribute Summary collapse
-
#party_size ⇒ Object
Returns the value of attribute party_size.
-
#restaurant ⇒ Object
Returns the value of attribute restaurant.
Class Method Summary collapse
Instance Method Summary collapse
- #end_time ⇒ Object
-
#initialize(restaurant_id) ⇒ GetEndTime
constructor
A new instance of GetEndTime.
- #start_time ⇒ Object
- #start_time=(time) ⇒ Object
Constructor Details
#initialize(restaurant_id) ⇒ GetEndTime
Returns a new instance of GetEndTime.
14 15 16 17 18 |
# File 'app/my_lib/receptionist/get_end_time.rb', line 14 def initialize(restaurant_id) raise InvalidRestaurant unless restaurant_id.is_a?(Integer) self.restaurant = Restaurant.fetch(restaurant_id) end |
Instance Attribute Details
#party_size ⇒ Object
Returns the value of attribute party_size.
10 11 12 |
# File 'app/my_lib/receptionist/get_end_time.rb', line 10 def party_size @party_size end |
#restaurant ⇒ Object
Returns the value of attribute restaurant.
10 11 12 |
# File 'app/my_lib/receptionist/get_end_time.rb', line 10 def restaurant @restaurant end |
Class Method Details
.determine_end_time_from_reservation(reservation) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/my_lib/receptionist/get_end_time.rb', line 20 def self.determine_end_time_from_reservation(reservation) duration = if reservation.package.present? reservation.package[:package_data].map do |item| rest_pack = HhPackage::RestaurantPackage.fetch(item[:restaurant_package_id]) rest_pack.package.reservation_duration.to_i end.max else reservation.restaurant.res_duration.to_i end duration = 15 if duration.zero? || duration.nil? start_time = reservation.start_time if start_time.blank? time_zone = reservation.restaurant&.time_zone.presence || Time::THAILAND_ZONE start_time = Time.use_zone(time_zone) do Time.zone.tomorrow.at_beginning_of_day + 19.hours end end start_time + duration.to_i.minutes end |
Instance Method Details
#end_time ⇒ Object
49 50 51 52 53 54 |
# File 'app/my_lib/receptionist/get_end_time.rb', line 49 def end_time raise InvalidSchedule, 'set start time first' unless start_time.is_a?(String) et_string = original_start_time + restaurant_res_duration.to_i.minutes et_string.strftime('%H:%M') end |
#start_time ⇒ Object
40 41 42 |
# File 'app/my_lib/receptionist/get_end_time.rb', line 40 def start_time @st_string end |
#start_time=(time) ⇒ Object
44 45 46 47 |
# File 'app/my_lib/receptionist/get_end_time.rb', line 44 def start_time=(time) self.original_start_time = normalize_time(time) @st_string = original_start_time.strftime('%H:%M') end |