Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Resources::Trip
- Defined in:
- app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb
Instance Attribute Summary collapse
-
#arrival_time ⇒ Object
Returns the value of attribute arrival_time.
-
#currency_code ⇒ Object
Returns the value of attribute currency_code.
-
#departure_time ⇒ Object
Returns the value of attribute departure_time.
-
#destination_id ⇒ Object
Returns the value of attribute destination_id.
-
#destination_name ⇒ Object
Returns the value of attribute destination_name.
-
#from_stop_id ⇒ Object
Returns the value of attribute from_stop_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#instant_book ⇒ Object
Returns the value of attribute instant_book.
-
#local_price ⇒ Object
Returns the value of attribute local_price.
-
#non_local_price ⇒ Object
Returns the value of attribute non_local_price.
-
#number_of_seats ⇒ Object
Returns the value of attribute number_of_seats.
-
#on_date ⇒ Object
Returns the value of attribute on_date.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#origin_id ⇒ Object
Returns the value of attribute origin_id.
-
#origin_name ⇒ Object
Returns the value of attribute origin_name.
-
#price ⇒ Object
Returns the value of attribute price.
-
#route_id ⇒ Object
Returns the value of attribute route_id.
-
#route_type ⇒ Object
Returns the value of attribute route_type.
-
#seats_remaining ⇒ Object
Returns the value of attribute seats_remaining.
-
#service_available ⇒ Object
Returns the value of attribute service_available.
-
#service_calendar ⇒ Object
Returns the value of attribute service_calendar.
-
#stop_times ⇒ Object
Returns the value of attribute stop_times.
-
#to_stop_id ⇒ Object
Returns the value of attribute to_stop_id.
-
#travel_duration ⇒ Object
Returns the value of attribute travel_duration.
-
#trip_id ⇒ Object
Returns the value of attribute trip_id.
-
#type ⇒ Object
Returns the value of attribute type.
-
#vehicle_type ⇒ Object
Returns the value of attribute vehicle_type.
Instance Method Summary collapse
- #amenities ⇒ Object
- #arrival_time_formatted ⇒ Object
- #available_seats ⇒ Object
-
#departure_time_formatted ⇒ Object
Time helpers - departure_time is in seconds from midnight.
- #destination_location_id ⇒ Object
- #destination_location_name ⇒ Object
- #destination_stop ⇒ Object
- #destination_stop_id ⇒ Object
- #destination_stop_lat ⇒ Object
- #destination_stop_lon ⇒ Object
- #destination_stop_name ⇒ Object
- #display_route ⇒ Object
- #display_schedule ⇒ Object
-
#initialize(attributes = {}) ⇒ Trip
constructor
A new instance of Trip.
-
#operator_id ⇒ Object
Operator accessors.
- #operator_logo ⇒ Object
- #operator_name ⇒ Object
- #origin_location_id ⇒ Object
- #origin_location_name ⇒ Object
-
#origin_stop ⇒ Object
Stop times accessors.
- #origin_stop_id ⇒ Object
- #origin_stop_lat ⇒ Object
- #origin_stop_lon ⇒ Object
- #origin_stop_name ⇒ Object
- #sync_identifier ⇒ Object
- #to_h ⇒ Object
- #vehicle_type_code ⇒ Object
-
#vehicle_type_id ⇒ Object
Vehicle accessors.
- #vehicle_type_name ⇒ Object
- #vehicle_type_route_type ⇒ Object
- #vehicle_type_type_name ⇒ Object
Methods inherited from Base
from_json_api, from_json_api_item, from_json_api_single
Constructor Details
#initialize(attributes = {}) ⇒ Trip
Returns a new instance of Trip.
31 32 33 34 35 36 37 38 39 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 31 def initialize(attributes = {}) super(attributes) @operator = attributes['operator'] if attributes['operator'].is_a?(Hash) @vehicle_type = attributes['vehicle_type'] if attributes['vehicle_type'].is_a?(Hash) @stop_times = attributes['stop_times'] if attributes['stop_times'].is_a?(Array) @price = attributes['price'] if attributes['price'].is_a?(Hash) @service_calendar = attributes['service_calendar'] if attributes['service_calendar'].is_a?(Hash) end |
Instance Attribute Details
#arrival_time ⇒ Object
Returns the value of attribute arrival_time.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def arrival_time @arrival_time end |
#currency_code ⇒ Object
Returns the value of attribute currency_code.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def currency_code @currency_code end |
#departure_time ⇒ Object
Returns the value of attribute departure_time.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def departure_time @departure_time end |
#destination_id ⇒ Object
Returns the value of attribute destination_id.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def destination_id @destination_id end |
#destination_name ⇒ Object
Returns the value of attribute destination_name.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def destination_name @destination_name end |
#from_stop_id ⇒ Object
Returns the value of attribute from_stop_id.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def from_stop_id @from_stop_id end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def id @id end |
#instant_book ⇒ Object
Returns the value of attribute instant_book.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def instant_book @instant_book end |
#local_price ⇒ Object
Returns the value of attribute local_price.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def local_price @local_price end |
#non_local_price ⇒ Object
Returns the value of attribute non_local_price.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def non_local_price @non_local_price end |
#number_of_seats ⇒ Object
Returns the value of attribute number_of_seats.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def number_of_seats @number_of_seats end |
#on_date ⇒ Object
Returns the value of attribute on_date.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def on_date @on_date end |
#operator ⇒ Object
Returns the value of attribute operator.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def operator @operator end |
#origin_id ⇒ Object
Returns the value of attribute origin_id.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def origin_id @origin_id end |
#origin_name ⇒ Object
Returns the value of attribute origin_name.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def origin_name @origin_name end |
#price ⇒ Object
Returns the value of attribute price.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def price @price end |
#route_id ⇒ Object
Returns the value of attribute route_id.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def route_id @route_id end |
#route_type ⇒ Object
Returns the value of attribute route_type.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def route_type @route_type end |
#seats_remaining ⇒ Object
Returns the value of attribute seats_remaining.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def seats_remaining @seats_remaining end |
#service_available ⇒ Object
Returns the value of attribute service_available.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def service_available @service_available end |
#service_calendar ⇒ Object
Returns the value of attribute service_calendar.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def service_calendar @service_calendar end |
#stop_times ⇒ Object
Returns the value of attribute stop_times.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def stop_times @stop_times end |
#to_stop_id ⇒ Object
Returns the value of attribute to_stop_id.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def to_stop_id @to_stop_id end |
#travel_duration ⇒ Object
Returns the value of attribute travel_duration.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def travel_duration @travel_duration end |
#trip_id ⇒ Object
Returns the value of attribute trip_id.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def trip_id @trip_id end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def type @type end |
#vehicle_type ⇒ Object
Returns the value of attribute vehicle_type.
3 4 5 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 3 def vehicle_type @vehicle_type end |
Instance Method Details
#amenities ⇒ Object
67 68 69 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 67 def amenities @vehicle_type&.dig('amenities') || [] end |
#arrival_time_formatted ⇒ Object
154 155 156 157 158 159 160 161 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 154 def arrival_time_formatted return nil unless @arrival_time seconds = @arrival_time.to_i hours = seconds / 3600 minutes = (seconds % 3600) / 60 format('%<hours>02d:%<minutes>02d', hours: hours, minutes: minutes) end |
#available_seats ⇒ Object
79 80 81 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 79 def available_seats seats_remaining end |
#departure_time_formatted ⇒ Object
Time helpers - departure_time is in seconds from midnight
145 146 147 148 149 150 151 152 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 145 def departure_time_formatted return nil unless @departure_time seconds = @departure_time.to_i hours = seconds / 3600 minutes = (seconds % 3600) / 60 format('%<hours>02d:%<minutes>02d', hours: hours, minutes: minutes) end |
#destination_location_id ⇒ Object
104 105 106 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 104 def destination_location_id destination_stop&.dig('location', 'id') end |
#destination_location_name ⇒ Object
108 109 110 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 108 def destination_location_name destination_stop&.dig('location', 'name') end |
#destination_stop ⇒ Object
92 93 94 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 92 def destination_stop @stop_times&.last end |
#destination_stop_id ⇒ Object
128 129 130 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 128 def destination_stop_id destination_stop&.dig('stop', 'id') end |
#destination_stop_lat ⇒ Object
136 137 138 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 136 def destination_stop_lat destination_stop&.dig('stop', 'lat') end |
#destination_stop_lon ⇒ Object
140 141 142 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 140 def destination_stop_lon destination_stop&.dig('stop', 'lon') end |
#destination_stop_name ⇒ Object
132 133 134 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 132 def destination_stop_name destination_stop&.dig('stop', 'name') end |
#display_route ⇒ Object
163 164 165 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 163 def display_route "#{origin_location_name} → #{destination_location_name}" end |
#display_schedule ⇒ Object
167 168 169 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 167 def display_schedule "#{departure_time_formatted} - #{arrival_time_formatted}" end |
#operator_id ⇒ Object
Operator accessors
42 43 44 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 42 def operator_id @operator&.dig('id') end |
#operator_logo ⇒ Object
50 51 52 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 50 def operator_logo @operator&.dig('logo', 'thumb') end |
#operator_name ⇒ Object
46 47 48 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 46 def operator_name @operator&.dig('name') end |
#origin_location_id ⇒ Object
96 97 98 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 96 def origin_location_id origin_stop&.dig('location', 'id') end |
#origin_location_name ⇒ Object
100 101 102 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 100 def origin_location_name origin_stop&.dig('location', 'name') end |
#origin_stop ⇒ Object
Stop times accessors
88 89 90 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 88 def origin_stop @stop_times&.first end |
#origin_stop_id ⇒ Object
112 113 114 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 112 def origin_stop_id origin_stop&.dig('stop', 'id') end |
#origin_stop_lat ⇒ Object
120 121 122 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 120 def origin_stop_lat origin_stop&.dig('stop', 'lat') end |
#origin_stop_lon ⇒ Object
124 125 126 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 124 def origin_stop_lon origin_stop&.dig('stop', 'lon') end |
#origin_stop_name ⇒ Object
116 117 118 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 116 def origin_stop_name origin_stop&.dig('stop', 'name') end |
#sync_identifier ⇒ Object
83 84 85 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 83 def sync_identifier trip_id || id end |
#to_h ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 171 def to_h { id: id, type: type, trip_id: trip_id, on_date: on_date, departure_time: departure_time, arrival_time: arrival_time, travel_duration: travel_duration, local_price: local_price, non_local_price: non_local_price, currency_code: currency_code, seats_remaining: seats_remaining, number_of_seats: number_of_seats, route_type: route_type, route_id: route_id, from_stop_id: from_stop_id, to_stop_id: to_stop_id, instant_book: instant_book, service_available: service_available, operator: operator, vehicle_type: vehicle_type, stop_times: stop_times, price: price, service_calendar: service_calendar }.compact end |
#vehicle_type_code ⇒ Object
63 64 65 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 63 def vehicle_type_code @vehicle_type&.dig('code') end |
#vehicle_type_id ⇒ Object
Vehicle accessors
55 56 57 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 55 def vehicle_type_id @vehicle_type&.dig('id') end |
#vehicle_type_name ⇒ Object
59 60 61 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 59 def vehicle_type_name @vehicle_type&.dig('name') end |
#vehicle_type_route_type ⇒ Object
71 72 73 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 71 def vehicle_type_route_type @vehicle_type&.dig('route_type') end |
#vehicle_type_type_name ⇒ Object
75 76 77 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/trip.rb', line 75 def vehicle_type_type_name @vehicle_type&.dig('type_name') end |