Class: SpreeCmCommissioner::Integrations::Larryta::Resources::Schedule
- Defined in:
- app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb
Overview
Represents a trip schedule from Larryta API
Instance Attribute Summary collapse
-
#bus_id ⇒ Object
Returns the value of attribute bus_id.
-
#bus_type_data ⇒ Object
readonly
Returns the value of attribute bus_type_data.
-
#bus_type_id ⇒ Object
Returns the value of attribute bus_type_id.
-
#commission ⇒ Object
Returns the value of attribute commission.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#direction_data ⇒ Object
readonly
Returns the value of attribute direction_data.
-
#direction_id ⇒ Object
Returns the value of attribute direction_id.
-
#discount ⇒ Object
Returns the value of attribute discount.
-
#net_price ⇒ Object
Returns the value of attribute net_price.
-
#sche_date ⇒ Object
Returns the value of attribute sche_date.
-
#sche_time ⇒ Object
Returns the value of attribute sche_time.
-
#schedule_id ⇒ Object
Returns the value of attribute schedule_id.
-
#total_available ⇒ Object
Returns the value of attribute total_available.
-
#total_unavailable ⇒ Object
Returns the value of attribute total_unavailable.
-
#unit_price ⇒ Object
Returns the value of attribute unit_price.
Instance Method Summary collapse
-
#arrival_datetime ⇒ Object
Returns the arrival datetime.
-
#arrival_time ⇒ Object
Returns the arrival time.
-
#availability_summary ⇒ Object
Returns availability summary.
-
#bus_capacity ⇒ Object
Returns the bus seat capacity.
-
#bus_image_url ⇒ Object
Returns the bus type image URL.
-
#bus_name ⇒ Object
Returns the bus name.
-
#date ⇒ Object
Returns the departure date.
-
#departure_datetime ⇒ Object
Returns the departure datetime.
-
#direction_code ⇒ Object
Returns the direction code.
-
#display_name ⇒ Object
Returns the display name for this schedule.
-
#from_location_name ⇒ Object
Returns the from location name.
-
#id ⇒ Object
Returns the schedule ID.
-
#initialize(data) ⇒ Schedule
constructor
rubocop:disable Lint/MissingSuper.
-
#night_bus? ⇒ Boolean
Returns whether this is a night bus.
-
#pricing_summary ⇒ Object
Returns pricing summary.
-
#time ⇒ Object
Returns the departure time.
-
#to_h ⇒ Object
Returns a hash representation.
-
#to_location_name ⇒ Object
Returns the to location name.
Methods inherited from Base
Constructor Details
#initialize(data) ⇒ Schedule
rubocop:disable Lint/MissingSuper
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 9 def initialize(data) # rubocop:disable Lint/MissingSuper @schedule_id = data['schedule_id'] @sche_date = data['sche_date'] @sche_time = data['sche_time'] @bus_type_id = data['bus_type_id'] @direction_id = data['direction_id'] @bus_id = data['bus_id'] prices = data['prices'] || {} @unit_price = prices['unit_price'] @discount = prices['discount'] @commission = prices['commission'] @net_price = prices['net_price'] @currency = prices['currency'] || 'KHR' @direction_data = data['direction'] || {} @total_unavailable = data['total_unavailable'] @bus_type_data = data['bus_type'] || {} @total_available = data['total_available'] end |
Instance Attribute Details
#bus_id ⇒ Object
Returns the value of attribute bus_id.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def bus_id @bus_id end |
#bus_type_data ⇒ Object (readonly)
Returns the value of attribute bus_type_data.
7 8 9 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 7 def bus_type_data @bus_type_data end |
#bus_type_id ⇒ Object
Returns the value of attribute bus_type_id.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def bus_type_id @bus_type_id end |
#commission ⇒ Object
Returns the value of attribute commission.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def commission @commission end |
#currency ⇒ Object
Returns the value of attribute currency.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def currency @currency end |
#direction_data ⇒ Object (readonly)
Returns the value of attribute direction_data.
7 8 9 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 7 def direction_data @direction_data end |
#direction_id ⇒ Object
Returns the value of attribute direction_id.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def direction_id @direction_id end |
#discount ⇒ Object
Returns the value of attribute discount.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def discount @discount end |
#net_price ⇒ Object
Returns the value of attribute net_price.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def net_price @net_price end |
#sche_date ⇒ Object
Returns the value of attribute sche_date.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def sche_date @sche_date end |
#sche_time ⇒ Object
Returns the value of attribute sche_time.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def sche_time @sche_time end |
#schedule_id ⇒ Object
Returns the value of attribute schedule_id.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def schedule_id @schedule_id end |
#total_available ⇒ Object
Returns the value of attribute total_available.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def total_available @total_available end |
#total_unavailable ⇒ Object
Returns the value of attribute total_unavailable.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def total_unavailable @total_unavailable end |
#unit_price ⇒ Object
Returns the value of attribute unit_price.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 4 def unit_price @unit_price end |
Instance Method Details
#arrival_datetime ⇒ Object
Returns the arrival datetime
56 57 58 59 60 61 62 63 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 56 def arrival_datetime return nil unless arrival_time # Parse arrival time and add to departure date arrival_hour, arrival_minute = arrival_time.split(':').map(&:to_i) departure = departure_datetime Time.zone.local(departure.year, departure.month, departure.day, arrival_hour, arrival_minute) end |
#arrival_time ⇒ Object
Returns the arrival time
51 52 53 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 51 def arrival_time direction_data['arrival_time'] end |
#availability_summary ⇒ Object
Returns availability summary
117 118 119 120 121 122 123 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 117 def availability_summary { total_seats: bus_capacity, available: total_available, unavailable: total_unavailable } end |
#bus_capacity ⇒ Object
Returns the bus seat capacity
86 87 88 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 86 def bus_capacity bus_type_data['seat_num'] end |
#bus_image_url ⇒ Object
Returns the bus type image URL
91 92 93 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 91 def bus_image_url bus_type_data['image'] end |
#bus_name ⇒ Object
Returns the bus name
81 82 83 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 81 def bus_name bus_type_data['bus_name'] end |
#date ⇒ Object
Returns the departure date
36 37 38 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 36 def date sche_date end |
#departure_datetime ⇒ Object
Returns the departure datetime
46 47 48 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 46 def departure_datetime Time.zone.parse("#{date} #{time}") end |
#direction_code ⇒ Object
Returns the direction code
66 67 68 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 66 def direction_code direction_data['dire_code'] end |
#display_name ⇒ Object
Returns the display name for this schedule
101 102 103 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 101 def display_name "#{from_location_name} → #{to_location_name} - #{date} #{time}" end |
#from_location_name ⇒ Object
Returns the from location name
71 72 73 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 71 def from_location_name direction_data.dig('from_location', 'loca_name') end |
#id ⇒ Object
Returns the schedule ID
31 32 33 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 31 def id schedule_id end |
#night_bus? ⇒ Boolean
Returns whether this is a night bus
96 97 98 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 96 def night_bus? bus_type_data['is_night_bus'] == 1 end |
#pricing_summary ⇒ Object
Returns pricing summary
106 107 108 109 110 111 112 113 114 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 106 def pricing_summary { unit_price: unit_price, discount: discount, commission: commission, net_price: net_price, currency: currency } end |
#time ⇒ Object
Returns the departure time
41 42 43 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 41 def time sche_time end |
#to_h ⇒ Object
Returns a hash representation
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 126 def to_h { id: id, date: date, time: time, departure_datetime: departure_datetime, arrival_time: arrival_time, arrival_datetime: arrival_datetime, bus_type_id: bus_type_id, direction_id: direction_id, bus_id: bus_id, direction_code: direction_code, from_location_name: from_location_name, to_location_name: to_location_name, bus_name: bus_name, bus_capacity: bus_capacity, bus_image_url: bus_image_url, night_bus: night_bus?, pricing: pricing_summary, availability: availability_summary, display_name: display_name } end |
#to_location_name ⇒ Object
Returns the to location name
76 77 78 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/schedule.rb', line 76 def to_location_name direction_data.dig('to_location', 'loca_name') end |