Class: SpreeCmCommissioner::TripResult
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::TripResult
- Defined in:
- lib/spree_cm_commissioner/trip_result.rb
Instance Attribute Summary collapse
-
#allow_seat_selection ⇒ Object
Returns the value of attribute allow_seat_selection.
-
#amenities ⇒ Object
Returns the value of attribute amenities.
-
#compare_at_price ⇒ Object
Returns the value of attribute compare_at_price.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#departure_time ⇒ Object
Returns the value of attribute departure_time.
-
#destination_place ⇒ Object
Returns the value of attribute destination_place.
-
#distance ⇒ Object
Returns the value of attribute distance.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#featured_until ⇒ Object
Returns the value of attribute featured_until.
-
#has_return_trip_globally ⇒ Object
Returns the value of attribute has_return_trip_globally.
-
#has_return_trip_in_vendor ⇒ Object
Returns the value of attribute has_return_trip_in_vendor.
-
#id ⇒ Object
Returns the value of attribute id.
-
#max_capacity ⇒ Object
Returns the value of attribute max_capacity.
-
#offset_days ⇒ Object
Returns the value of attribute offset_days.
-
#open_dated_compare_at_price ⇒ Object
Returns the value of attribute open_dated_compare_at_price.
-
#open_dated_price ⇒ Object
Returns the value of attribute open_dated_price.
-
#open_dated_product_id ⇒ Object
Returns the value of attribute open_dated_product_id.
-
#origin_place ⇒ Object
Returns the value of attribute origin_place.
-
#price ⇒ Object
Returns the value of attribute price.
-
#product_id ⇒ Object
Returns the value of attribute product_id.
-
#quantity_available ⇒ Object
Returns the value of attribute quantity_available.
-
#route_type ⇒ Object
Returns the value of attribute route_type.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#stops ⇒ Object
Returns the value of attribute stops.
-
#vehicle_type ⇒ Object
Returns the value of attribute vehicle_type.
-
#vehicle_type_id ⇒ Object
Returns the value of attribute vehicle_type_id.
-
#vendor ⇒ Object
Returns the value of attribute vendor.
-
#vendor_id ⇒ Object
Returns the value of attribute vendor_id.
Class Method Summary collapse
Instance Method Summary collapse
- #amenity_ids ⇒ Object
- #arrival_time ⇒ Object
- #boarding ⇒ Object
-
#cache_key_with_version ⇒ Object
Enable serializer-level caching (like ActiveRecord’s cache_key_with_version) Create a version hash based on attributes that matter for caching.
-
#compare_at_amount ⇒ Object
Deprecated for backwards compatibility.
- #display_compare_at_price ⇒ Object
- #display_price ⇒ Object
- #drop_off ⇒ Object
- #duration_in_hms ⇒ Object
- #duration_with_offset ⇒ Object
-
#initialize(options = {}) ⇒ TripResult
constructor
A new instance of TripResult.
- #total_sold ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TripResult
Returns a new instance of TripResult.
11 12 13 14 15 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 11 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end end |
Instance Attribute Details
#allow_seat_selection ⇒ Object
Returns the value of attribute allow_seat_selection.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def allow_seat_selection @allow_seat_selection end |
#amenities ⇒ Object
Returns the value of attribute amenities.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def amenities @amenities end |
#compare_at_price ⇒ Object
Returns the value of attribute compare_at_price.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def compare_at_price @compare_at_price end |
#currency ⇒ Object
Returns the value of attribute currency.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def currency @currency end |
#departure_time ⇒ Object
Returns the value of attribute departure_time.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def departure_time @departure_time end |
#destination_place ⇒ Object
Returns the value of attribute destination_place.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def destination_place @destination_place end |
#distance ⇒ Object
Returns the value of attribute distance.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def distance @distance end |
#duration ⇒ Object
Returns the value of attribute duration.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def duration @duration end |
#featured_until ⇒ Object
Returns the value of attribute featured_until.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def featured_until @featured_until end |
#has_return_trip_globally ⇒ Object
Returns the value of attribute has_return_trip_globally.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def has_return_trip_globally @has_return_trip_globally end |
#has_return_trip_in_vendor ⇒ Object
Returns the value of attribute has_return_trip_in_vendor.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def has_return_trip_in_vendor @has_return_trip_in_vendor end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def id @id end |
#max_capacity ⇒ Object
Returns the value of attribute max_capacity.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def max_capacity @max_capacity end |
#offset_days ⇒ Object
Returns the value of attribute offset_days.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def offset_days @offset_days end |
#open_dated_compare_at_price ⇒ Object
Returns the value of attribute open_dated_compare_at_price.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def open_dated_compare_at_price @open_dated_compare_at_price end |
#open_dated_price ⇒ Object
Returns the value of attribute open_dated_price.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def open_dated_price @open_dated_price end |
#open_dated_product_id ⇒ Object
Returns the value of attribute open_dated_product_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def open_dated_product_id @open_dated_product_id end |
#origin_place ⇒ Object
Returns the value of attribute origin_place.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def origin_place @origin_place end |
#price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def price @price end |
#product_id ⇒ Object
Returns the value of attribute product_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def product_id @product_id end |
#quantity_available ⇒ Object
Returns the value of attribute quantity_available.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def quantity_available @quantity_available end |
#route_type ⇒ Object
Returns the value of attribute route_type.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def route_type @route_type end |
#sequence ⇒ Object
Returns the value of attribute sequence.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def sequence @sequence end |
#stops ⇒ Object
Returns the value of attribute stops.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def stops @stops end |
#vehicle_type ⇒ Object
Returns the value of attribute vehicle_type.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def vehicle_type @vehicle_type end |
#vehicle_type_id ⇒ Object
Returns the value of attribute vehicle_type_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def vehicle_type_id @vehicle_type_id end |
#vendor ⇒ Object
Returns the value of attribute vendor.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def vendor @vendor end |
#vendor_id ⇒ Object
Returns the value of attribute vendor_id.
3 4 5 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 3 def vendor_id @vendor_id end |
Class Method Details
.from_trip(trip) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 17 def self.from_trip(trip) return nil if trip.nil? vehicle_type = trip&.vehicle_type vendor = trip&.vendor new( id: trip&.id, departure_time: trip&.departure_time, duration: trip&.duration, distance: trip&.distance, allow_seat_selection: trip&.allow_seat_selection, route_type: trip&.route_type, featured_until: trip&.featured_until, origin_place: { id: trip&.origin_place_id, name: trip&.origin_place_name }, destination_place: { id: trip&.destination_place_id, name: trip&.destination_place_name }, vehicle_type_id: trip&.vehicle_type_id, vehicle_type: vehicle_type, vendor_id: trip&.vendor_id, vendor: vendor, product_id: trip&.product_id, price: trip&.price, currency: trip&.currency, compare_at_price: trip&.compare_at_price, offset_days: trip.try(:offset_days) || 0, stops: build_stops_from_trip(trip), quantity_available: trip&.quantity_available, max_capacity: trip&.max_capacity, amenities: (trip.vehicle_type&.option_values || []), open_dated_product_id: trip&.open_dated_product_id, open_dated_price: trip&.open_dated_price, open_dated_compare_at_price: trip&.open_dated_compare_at_price, has_return_trip_globally: trip.has_return_trip_globally, has_return_trip_in_vendor: trip.has_return_trip_in_vendor ) end |
Instance Method Details
#amenity_ids ⇒ Object
65 66 67 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 65 def amenity_ids amenities&.map(&:id) || [] end |
#arrival_time ⇒ Object
94 95 96 97 98 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 94 def arrival_time return nil if departure_time.nil? || duration_with_offset.nil? departure_time + duration_with_offset.seconds end |
#boarding ⇒ Object
74 75 76 77 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 74 def boarding stop = Array(stops).find { |s| s.is_a?(Hash) && (s[:allow_boarding] || s['allow_boarding']) } normalize_stop(stop) end |
#cache_key_with_version ⇒ Object
Enable serializer-level caching (like ActiveRecord’s cache_key_with_version) Create a version hash based on attributes that matter for caching
120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 120 def cache_key_with_version version_parts = [ id, price, quantity_available, max_capacity, departure_time&.to_i, open_dated_product_id ].compact.join('-') version_hash = Digest::MD5.hexdigest(version_parts) "trip_results/#{id}-#{version_hash}" end |
#compare_at_amount ⇒ Object
Deprecated for backwards compatibility
70 71 72 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 70 def compare_at_amount compare_at_price end |
#display_compare_at_price ⇒ Object
112 113 114 115 116 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 112 def display_compare_at_price return nil if compare_at_price.nil? || currency.nil? Spree::Money.new(compare_at_price, currency: currency).to_s end |
#display_price ⇒ Object
106 107 108 109 110 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 106 def display_price return nil if price.nil? || currency.nil? Spree::Money.new(price, currency: currency).to_s end |
#drop_off ⇒ Object
79 80 81 82 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 79 def drop_off stop = Array(stops).select { |s| s.is_a?(Hash) && (s[:allow_drop_off] || s['allow_drop_off']) }.last normalize_stop(stop) end |
#duration_in_hms ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 84 def duration_in_hms total_seconds = duration_with_offset return { hours: 0, minutes: 0, seconds: 0 } if total_seconds.nil? hours = total_seconds / 3600 minutes = (total_seconds % 3600) / 60 seconds = total_seconds % 60 { hours: hours, minutes: minutes, seconds: seconds } end |
#duration_with_offset ⇒ Object
100 101 102 103 104 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 100 def duration_with_offset return nil if duration.nil? duration + offset_days.to_i.days end |
#total_sold ⇒ Object
59 60 61 62 63 |
# File 'lib/spree_cm_commissioner/trip_result.rb', line 59 def total_sold return if max_capacity.nil? || quantity_available.nil? max_capacity - quantity_available end |