Class: SpreeCmCommissioner::Integrations::VireakBuntham::Resources::Schedule

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Base

from_api_response

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

#arrivalObject

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_listObject

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_pointObject

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_addressObject

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_idObject

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_latsObject

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_longsObject

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

#departureObject

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

#descriptionObject

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_listObject

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_pointObject

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_addressObject

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_idObject

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_latsObject

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_longsObject

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

#durationObject

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

#idObject

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

#priceObject

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_foreignerObject

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_endObject

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_endObject

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_priceObject

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_foreignerObject

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_startObject

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_priceObject

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_foreignerObject

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_startObject

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_availableObject

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

#statusObject

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_seatObject

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_typeObject

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_idObject

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

#currencyObject



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_hObject



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