Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Resources::InventoryItemStatus
- Inherits:
-
Base
- Object
- Base
- SpreeCmCommissioner::Integrations::BookMeBusV1::Resources::InventoryItemStatus
- Defined in:
- app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb
Instance Attribute Summary collapse
-
#amount ⇒ Object
Financials.
-
#arrival_time ⇒ Object
Schedule.
-
#contact_email ⇒ Object
Contact and participants.
-
#contact_phone ⇒ Object
Contact and participants.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#departure_date ⇒ Object
Schedule.
-
#departure_time ⇒ Object
Schedule.
-
#discount ⇒ Object
Financials.
-
#fare ⇒ Object
Financials.
-
#from_location ⇒ Object
Locations and stops.
-
#from_stop_time ⇒ Object
Returns the value of attribute from_stop_time.
-
#id ⇒ Object
Identity.
-
#number_of_seats ⇒ Object
Seats and vehicle.
-
#operator ⇒ Object
Contact and participants.
-
#paid_at ⇒ Object
Returns the value of attribute paid_at.
-
#raw_data ⇒ Object
Raw API response.
-
#reservation_cart ⇒ Object
Contact and participants.
-
#reservation_eticket_url ⇒ Object
URLs and timestamps.
-
#reservation_number ⇒ Object
Identity.
-
#reservation_qr_code_url ⇒ Object
URLs and timestamps.
-
#reserved_seats ⇒ Object
Seats and vehicle.
-
#seat_stops ⇒ Object
Seats and vehicle.
-
#status ⇒ Object
Identity.
-
#stop_times ⇒ Object
Returns the value of attribute stop_times.
-
#ticket_type ⇒ Object
Identity.
-
#to_location ⇒ Object
Locations and stops.
-
#to_stop_time ⇒ Object
Returns the value of attribute to_stop_time.
-
#type ⇒ Object
Identity.
-
#user ⇒ Object
Contact and participants.
-
#vehicle_type ⇒ Object
Seats and vehicle.
Instance Method Summary collapse
- #age ⇒ Object
- #arrival_time_formatted ⇒ Object
- #cart_id ⇒ Object
- #confirmed? ⇒ Boolean
- #departure_time_formatted ⇒ Object
- #destination_name ⇒ Object
-
#first_seat ⇒ Object
Get first reserved seat details.
- #gender ⇒ Object
-
#initialize(attributes = {}) ⇒ InventoryItemStatus
constructor
rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity.
- #nationality ⇒ Object
- #operator_name ⇒ Object
- #origin_name ⇒ Object
- #paid? ⇒ Boolean
- #passenger_name ⇒ Object
- #seat_label ⇒ Object
- #to_h ⇒ Object
- #vehicle_type_name ⇒ Object
Methods inherited from Base
from_json_api, from_json_api_item, from_json_api_single
Constructor Details
#initialize(attributes = {}) ⇒ InventoryItemStatus
rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 30 def initialize(attributes = {}) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity super(attributes) @raw_data = attributes @from_location = attributes['from_location'] || {} @to_location = attributes['to_location'] || {} @from_stop_time = attributes['from_stop_time'] || {} @to_stop_time = attributes['to_stop_time'] || {} @operator = attributes['operator'] || {} @reserved_seats = attributes['reserved_seats'] || {} @reservation_cart = attributes['reservation_cart'] || {} @stop_times = attributes['stop_times'] || [] @seat_stops = attributes['seat_stops'] || [] @user = attributes['user'] || {} @vehicle_type = attributes['vehicle_type'] || {} end |
Instance Attribute Details
#amount ⇒ Object
Financials
19 20 21 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 19 def amount @amount end |
#arrival_time ⇒ Object
Schedule
13 14 15 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 13 def arrival_time @arrival_time end |
#contact_email ⇒ Object
Contact and participants
22 23 24 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22 def contact_email @contact_email end |
#contact_phone ⇒ Object
Contact and participants
22 23 24 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22 def contact_phone @contact_phone end |
#created_at ⇒ Object
Returns the value of attribute created_at.
10 11 12 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10 def created_at @created_at end |
#departure_date ⇒ Object
Schedule
13 14 15 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 13 def departure_date @departure_date end |
#departure_time ⇒ Object
Schedule
13 14 15 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 13 def departure_time @departure_time end |
#discount ⇒ Object
Financials
19 20 21 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 19 def discount @discount end |
#fare ⇒ Object
Financials
19 20 21 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 19 def fare @fare end |
#from_location ⇒ Object
Locations and stops
9 10 11 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 9 def from_location @from_location end |
#from_stop_time ⇒ Object
Returns the value of attribute from_stop_time.
10 11 12 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10 def from_stop_time @from_stop_time end |
#id ⇒ Object
Identity
6 7 8 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6 def id @id end |
#number_of_seats ⇒ Object
Seats and vehicle
16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16 def number_of_seats @number_of_seats end |
#operator ⇒ Object
Contact and participants
22 23 24 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22 def operator @operator end |
#paid_at ⇒ Object
Returns the value of attribute paid_at.
10 11 12 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10 def paid_at @paid_at end |
#raw_data ⇒ Object
Raw API response
28 29 30 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 28 def raw_data @raw_data end |
#reservation_cart ⇒ Object
Contact and participants
22 23 24 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22 def reservation_cart @reservation_cart end |
#reservation_eticket_url ⇒ Object
URLs and timestamps
25 26 27 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 25 def reservation_eticket_url @reservation_eticket_url end |
#reservation_number ⇒ Object
Identity
6 7 8 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6 def reservation_number @reservation_number end |
#reservation_qr_code_url ⇒ Object
URLs and timestamps
25 26 27 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 25 def reservation_qr_code_url @reservation_qr_code_url end |
#reserved_seats ⇒ Object
Seats and vehicle
16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16 def reserved_seats @reserved_seats end |
#seat_stops ⇒ Object
Seats and vehicle
16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16 def seat_stops @seat_stops end |
#status ⇒ Object
Identity
6 7 8 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6 def status @status end |
#stop_times ⇒ Object
Returns the value of attribute stop_times.
10 11 12 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10 def stop_times @stop_times end |
#ticket_type ⇒ Object
Identity
6 7 8 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6 def ticket_type @ticket_type end |
#to_location ⇒ Object
Locations and stops
9 10 11 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 9 def to_location @to_location end |
#to_stop_time ⇒ Object
Returns the value of attribute to_stop_time.
10 11 12 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 10 def to_stop_time @to_stop_time end |
#type ⇒ Object
Identity
6 7 8 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 6 def type @type end |
#user ⇒ Object
Contact and participants
22 23 24 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 22 def user @user end |
#vehicle_type ⇒ Object
Seats and vehicle
16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 16 def vehicle_type @vehicle_type end |
Instance Method Details
#age ⇒ Object
70 71 72 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 70 def age first_seat&.dig('age') end |
#arrival_time_formatted ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 111 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 |
#cart_id ⇒ Object
98 99 100 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 98 def cart_id reservation_cart['id'] end |
#confirmed? ⇒ Boolean
78 79 80 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 78 def confirmed? paid? || status == 'confirmed' end |
#departure_time_formatted ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 102 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_name ⇒ Object
86 87 88 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 86 def destination_name to_location['name'] end |
#first_seat ⇒ Object
Get first reserved seat details
48 49 50 51 52 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 48 def first_seat return nil if reserved_seats.empty? reserved_seats.values.flatten.first end |
#gender ⇒ Object
66 67 68 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 66 def gender first_seat&.dig('gender') end |
#nationality ⇒ Object
62 63 64 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 62 def nationality first_seat&.dig('readable_nationality') || first_seat&.dig('nationality') end |
#operator_name ⇒ Object
90 91 92 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 90 def operator_name operator['name'] end |
#origin_name ⇒ Object
82 83 84 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 82 def origin_name from_location['name'] end |
#paid? ⇒ Boolean
74 75 76 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 74 def paid? status == 'paid' end |
#passenger_name ⇒ Object
54 55 56 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 54 def passenger_name first_seat&.dig('name') end |
#seat_label ⇒ Object
58 59 60 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 58 def seat_label first_seat&.dig('label') end |
#to_h ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 120 def to_h { id: id, reservation_number: reservation_number, status: status, passenger_name: passenger_name, seat_label: seat_label, origin: origin_name, destination: destination_name, departure_date: departure_date, departure_time: departure_time, arrival_time: arrival_time, fare: fare, amount: amount, contact_phone: contact_phone, contact_email: contact_email, operator: operator_name, vehicle_type: vehicle_type_name, nationality: nationality, gender: gender, age: age, qr_code_url: reservation_qr_code_url, eticket_url: reservation_eticket_url, paid_at: paid_at, created_at: created_at } end |
#vehicle_type_name ⇒ Object
94 95 96 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/inventory_item_status.rb', line 94 def vehicle_type_name vehicle_type['name'] end |