Class: SpreeCmCommissioner::Trip
- Includes:
- RouteType, StoreMetadata
- Defined in:
- app/models/spree_cm_commissioner/trip.rb
Constant Summary
Constants included from RouteType
Instance Attribute Summary collapse
-
#hours ⇒ Object
Returns the value of attribute hours.
-
#minutes ⇒ Object
Returns the value of attribute minutes.
-
#seconds ⇒ Object
Returns the value of attribute seconds.
Instance Method Summary collapse
- #arrival_time ⇒ Object
- #convert_duration_to_seconds ⇒ Object
- #direct_trips_cannot_have_board_to_trips ⇒ Object
- #display_name ⇒ Object
- #duration_in_hms ⇒ Object
- #multi_leg_trip_stops_must_have_board_to_trip ⇒ Object
- #open_dated? ⇒ Boolean
-
#open_dated_pair ⇒ Object
Find the open dated version of this trip’s product.
Instance Attribute Details
#hours ⇒ Object
Returns the value of attribute hours.
6 7 8 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 6 def hours @hours end |
#minutes ⇒ Object
Returns the value of attribute minutes.
6 7 8 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 6 def minutes @minutes end |
#seconds ⇒ Object
Returns the value of attribute seconds.
6 7 8 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 6 def seconds @seconds end |
Instance Method Details
#arrival_time ⇒ Object
89 90 91 92 93 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 89 def arrival_time return nil if departure_time.nil? || duration.nil? departure_time + duration.seconds end |
#convert_duration_to_seconds ⇒ Object
74 75 76 77 78 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 74 def convert_duration_to_seconds return if hours.blank? && minutes.blank? && seconds.blank? self.duration = (hours.to_i * 3600) + (minutes.to_i * 60) + seconds.to_i end |
#direct_trips_cannot_have_board_to_trips ⇒ Object
108 109 110 111 112 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 108 def direct_trips_cannot_have_board_to_trips return if board_to_trips.empty? errors.add(:board_to_trips, 'direct trips cannot have board_to_trips') end |
#display_name ⇒ Object
123 124 125 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 123 def display_name product&.name end |
#duration_in_hms ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 80 def duration_in_hms return { hours: 0, minutes: 0, seconds: 0 } if duration.nil? hours = duration / 3600 minutes = (duration % 3600) / 60 seconds = duration % 60 { hours: hours, minutes: minutes, seconds: seconds } end |
#multi_leg_trip_stops_must_have_board_to_trip ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 95 def multi_leg_trip_stops_must_have_board_to_trip return if trip_stops.blank? # Only validate non-final stops (all but the last one by sequence) # The final destination stop doesn't need a board_to_trip_id since there's no onward connection final_stop_id = trip_stops.max_by(&:sequence)&.id non_final_without_board = trip_stops.where.not(id: final_stop_id).exists?(board_to_trip_id: nil) return unless non_final_without_board errors.add(:trip_stops, 'all non-final trip stops must have board_to_trip_id for multi-leg trips') end |
#open_dated? ⇒ Boolean
114 115 116 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 114 def open_dated? is_open_dated == true end |
#open_dated_pair ⇒ Object
Find the open dated version of this trip’s product
119 120 121 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 119 def open_dated_pair open_dated_product end |