Class: SpreeCmCommissioner::Trip
- Includes:
- Integrations::IntegrationMappable, 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
- #featured? ⇒ Boolean
- #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.
7 8 9 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 7 def hours @hours end |
#minutes ⇒ Object
Returns the value of attribute minutes.
7 8 9 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 7 def minutes @minutes end |
#seconds ⇒ Object
Returns the value of attribute seconds.
7 8 9 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 7 def seconds @seconds end |
Instance Method Details
#arrival_time ⇒ Object
93 94 95 96 97 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 93 def arrival_time return nil if departure_time.nil? || duration.nil? departure_time + duration.seconds end |
#convert_duration_to_seconds ⇒ Object
78 79 80 81 82 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 78 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
112 113 114 115 116 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 112 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
127 128 129 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 127 def display_name product&.name end |
#duration_in_hms ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 84 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 |
#featured? ⇒ Boolean
131 132 133 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 131 def featured? featured_until.present? && featured_until >= Time.current end |
#multi_leg_trip_stops_must_have_board_to_trip ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 99 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
118 119 120 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 118 def open_dated? is_open_dated == true end |
#open_dated_pair ⇒ Object
Find the open dated version of this trip’s product
123 124 125 |
# File 'app/models/spree_cm_commissioner/trip.rb', line 123 def open_dated_pair open_dated_product end |