Class: SpreeCmCommissioner::Integrations::VireakBuntham::Resources::Schedule
- Inherits:
-
Base
- Object
- Base
- SpreeCmCommissioner::Integrations::VireakBuntham::Resources::Schedule
- Defined in:
- app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb
Overview
Wraps a VET schedule item returned by POST /schedule/list (or listByDate).
Seat capacity fields:
totalSeat - total seats on the vehicle
seatAvailable - seats still available for booking
Price fields:
price - local (Khmer) base price
priceForeigner - foreigner base price
promotionPrice - local promo price (zero when no promo)
promotionPriceForeigner - foreigner promo price (zero when no promo)
promotionInternalPrice - local promo price for VET-app bookings
promotionInternalPriceForeigner- foreigner promo price for VET-app bookings
Effective prices are date-windowed by promotionStart/promotionEnd and promotionInternalStart/promotionInternalEnd respectively.
Instance Attribute Summary collapse
-
#arrival ⇒ Object
Returns the value of attribute arrival.
-
#boarding_list ⇒ Object
Returns the value of attribute boarding_list.
-
#boarding_point ⇒ Object
Returns the value of attribute boarding_point.
-
#boarding_point_address ⇒ Object
Returns the value of attribute boarding_point_address.
-
#boarding_point_id ⇒ Object
Returns the value of attribute boarding_point_id.
-
#boarding_point_lats ⇒ Object
Returns the value of attribute boarding_point_lats.
-
#boarding_point_longs ⇒ Object
Returns the value of attribute boarding_point_longs.
-
#departure ⇒ Object
Returns the value of attribute departure.
-
#description ⇒ Object
Returns the value of attribute description.
-
#drop_off_list ⇒ Object
Returns the value of attribute drop_off_list.
-
#drop_off_point ⇒ Object
Returns the value of attribute drop_off_point.
-
#drop_off_point_address ⇒ Object
Returns the value of attribute drop_off_point_address.
-
#drop_off_point_id ⇒ Object
Returns the value of attribute drop_off_point_id.
-
#drop_off_point_lats ⇒ Object
Returns the value of attribute drop_off_point_lats.
-
#drop_off_point_longs ⇒ Object
Returns the value of attribute drop_off_point_longs.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#id ⇒ Object
Returns the value of attribute id.
-
#price ⇒ Object
Returns the value of attribute price.
-
#price_foreigner ⇒ Object
Returns the value of attribute price_foreigner.
-
#promotion_end ⇒ Object
Returns the value of attribute promotion_end.
-
#promotion_internal_end ⇒ Object
Returns the value of attribute promotion_internal_end.
-
#promotion_internal_price ⇒ Object
Returns the value of attribute promotion_internal_price.
-
#promotion_internal_price_foreigner ⇒ Object
Returns the value of attribute promotion_internal_price_foreigner.
-
#promotion_internal_start ⇒ Object
Returns the value of attribute promotion_internal_start.
-
#promotion_price ⇒ Object
Returns the value of attribute promotion_price.
-
#promotion_price_foreigner ⇒ Object
Returns the value of attribute promotion_price_foreigner.
-
#promotion_start ⇒ Object
Returns the value of attribute promotion_start.
-
#seat_available ⇒ Object
Returns the value of attribute seat_available.
-
#status ⇒ Object
Returns the value of attribute status.
-
#total_seat ⇒ Object
Returns the value of attribute total_seat.
-
#transportation_type ⇒ Object
Returns the value of attribute transportation_type.
-
#transportation_type_id ⇒ Object
Returns the value of attribute transportation_type_id.
Instance Method Summary collapse
- #currency ⇒ Object
- #effective_foreigner_price(on_date) ⇒ Object
-
#effective_local_price(on_date) ⇒ Object
Returns the effective local price for the given departure date.
-
#initialize(data) ⇒ Schedule
constructor
rubocop:disable Lint/MissingSuper,Metrics/AbcSize,Metrics/MethodLength.
- #to_h ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(data) ⇒ Schedule
rubocop:disable Lint/MissingSuper,Metrics/AbcSize,Metrics/MethodLength
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 36 def initialize(data) # rubocop:disable Lint/MissingSuper,Metrics/AbcSize,Metrics/MethodLength @id = data['id'] @description = data['description'] @departure = data['departure'] @arrival = data['arrival'] @duration = data['duration'] @boarding_point = data['boardingPoint'] @boarding_point_id = data['boardingPointId'] @boarding_point_address = data['boardingPointAddress'] @boarding_point_lats = data['boardingPointLats'] @boarding_point_longs = data['boardingPointLongs'] @drop_off_point = data['dropOffPoint'] @drop_off_point_id = data['dropOffPointId'] @drop_off_point_address = data['dropOffPointAddress'] @drop_off_point_lats = data['dropOffPointLats'] @drop_off_point_longs = data['dropOffPointLongs'] @boarding_list = Array(data['boardingList']) @drop_off_list = Array(data['dropOffList']) @transportation_type = data['transportationType'] @transportation_type_id = data['transportationTypeId'] @total_seat = data['totalSeat'].to_i @seat_available = data['seatAvailable'].to_i @price = data['price'].to_f @price_foreigner = data['priceForeigner'].to_f @promotion_start = data['promotionStart'] @promotion_end = data['promotionEnd'] @promotion_price = data['promotionPrice'].to_f @promotion_price_foreigner = data['promotionPriceForeigner'].to_f @promotion_internal_start = data['promotionInternalStart'] @promotion_internal_end = data['promotionInternalEnd'] @promotion_internal_price = data['promotionInternalPrice'].to_f @promotion_internal_price_foreigner = data['promotionInternalPriceForeigner'].to_f @status = data['status'] end |
Instance Attribute Details
#arrival ⇒ Object
Returns the value of attribute arrival.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def arrival @arrival end |
#boarding_list ⇒ Object
Returns the value of attribute boarding_list.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def boarding_list @boarding_list end |
#boarding_point ⇒ Object
Returns the value of attribute boarding_point.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def boarding_point @boarding_point end |
#boarding_point_address ⇒ Object
Returns the value of attribute boarding_point_address.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def boarding_point_address @boarding_point_address end |
#boarding_point_id ⇒ Object
Returns the value of attribute boarding_point_id.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def boarding_point_id @boarding_point_id end |
#boarding_point_lats ⇒ Object
Returns the value of attribute boarding_point_lats.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def boarding_point_lats @boarding_point_lats end |
#boarding_point_longs ⇒ Object
Returns the value of attribute boarding_point_longs.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def boarding_point_longs @boarding_point_longs end |
#departure ⇒ Object
Returns the value of attribute departure.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def departure @departure end |
#description ⇒ Object
Returns the value of attribute description.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def description @description end |
#drop_off_list ⇒ Object
Returns the value of attribute drop_off_list.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def drop_off_list @drop_off_list end |
#drop_off_point ⇒ Object
Returns the value of attribute drop_off_point.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def drop_off_point @drop_off_point end |
#drop_off_point_address ⇒ Object
Returns the value of attribute drop_off_point_address.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def drop_off_point_address @drop_off_point_address end |
#drop_off_point_id ⇒ Object
Returns the value of attribute drop_off_point_id.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def drop_off_point_id @drop_off_point_id end |
#drop_off_point_lats ⇒ Object
Returns the value of attribute drop_off_point_lats.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def drop_off_point_lats @drop_off_point_lats end |
#drop_off_point_longs ⇒ Object
Returns the value of attribute drop_off_point_longs.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def drop_off_point_longs @drop_off_point_longs end |
#duration ⇒ Object
Returns the value of attribute duration.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def duration @duration end |
#id ⇒ Object
Returns the value of attribute id.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def id @id end |
#price ⇒ Object
Returns the value of attribute price.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def price @price end |
#price_foreigner ⇒ Object
Returns the value of attribute price_foreigner.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def price_foreigner @price_foreigner end |
#promotion_end ⇒ Object
Returns the value of attribute promotion_end.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_end @promotion_end end |
#promotion_internal_end ⇒ Object
Returns the value of attribute promotion_internal_end.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_internal_end @promotion_internal_end end |
#promotion_internal_price ⇒ Object
Returns the value of attribute promotion_internal_price.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_internal_price @promotion_internal_price end |
#promotion_internal_price_foreigner ⇒ Object
Returns the value of attribute promotion_internal_price_foreigner.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_internal_price_foreigner @promotion_internal_price_foreigner end |
#promotion_internal_start ⇒ Object
Returns the value of attribute promotion_internal_start.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_internal_start @promotion_internal_start end |
#promotion_price ⇒ Object
Returns the value of attribute promotion_price.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_price @promotion_price end |
#promotion_price_foreigner ⇒ Object
Returns the value of attribute promotion_price_foreigner.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_price_foreigner @promotion_price_foreigner end |
#promotion_start ⇒ Object
Returns the value of attribute promotion_start.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def promotion_start @promotion_start end |
#seat_available ⇒ Object
Returns the value of attribute seat_available.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def seat_available @seat_available end |
#status ⇒ Object
Returns the value of attribute status.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def status @status end |
#total_seat ⇒ Object
Returns the value of attribute total_seat.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def total_seat @total_seat end |
#transportation_type ⇒ Object
Returns the value of attribute transportation_type.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def transportation_type @transportation_type end |
#transportation_type_id ⇒ Object
Returns the value of attribute transportation_type_id.
21 22 23 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 21 def transportation_type_id @transportation_type_id end |
Instance Method Details
#currency ⇒ Object
97 98 99 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 97 def currency 'USD' end |
#effective_foreigner_price(on_date) ⇒ Object
90 91 92 93 94 95 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 90 def effective_foreigner_price(on_date) in_promo = in_promo_window?(promotion_start, promotion_end, on_date) return promotion_price_foreigner if in_promo && promotion_price_foreigner.positive? price_foreigner end |
#effective_local_price(on_date) ⇒ Object
Returns the effective local price for the given departure date. Promo prices apply when the date is inside [promotion_start, promotion_end] AND the promo amount is positive.
83 84 85 86 87 88 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 83 def effective_local_price(on_date) in_promo = in_promo_window?(promotion_start, promotion_end, on_date) return promotion_price if in_promo && promotion_price.positive? price end |
#to_h ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/schedule.rb', line 101 def to_h { id: id, description: description, departure: departure, arrival: arrival, duration: duration, boarding_point_id: boarding_point_id, drop_off_point_id: drop_off_point_id, transportation_type: transportation_type, transportation_type_id: transportation_type_id, total_seat: total_seat, seat_available: seat_available, price: price, price_foreigner: price_foreigner, promotion_start: promotion_start, promotion_end: promotion_end, promotion_price: promotion_price, promotion_price_foreigner: promotion_price_foreigner, status: status } end |