Class: SpreeCmCommissioner::Integrations::Larryta::Resources::Booking
- Defined in:
- app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb
Overview
Represents a confirmed booking from Larryta API
Instance Attribute Summary collapse
-
#arrival_time ⇒ Object
Returns the value of attribute arrival_time.
-
#booking_code ⇒ Object
Returns the value of attribute booking_code.
-
#booking_date ⇒ Object
Returns the value of attribute booking_date.
-
#booking_status ⇒ Object
Returns the value of attribute booking_status.
-
#bus_type ⇒ Object
Returns the value of attribute bus_type.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#departure_date ⇒ Object
Returns the value of attribute departure_date.
-
#departure_time ⇒ Object
Returns the value of attribute departure_time.
-
#direction_info ⇒ Object
readonly
Returns the value of attribute direction_info.
-
#msg ⇒ Object
Returns the value of attribute msg.
-
#passenger_name ⇒ Object
Returns the value of attribute passenger_name.
-
#payment_date ⇒ Object
Returns the value of attribute payment_date.
-
#payment_status ⇒ Object
Returns the value of attribute payment_status.
-
#seat_number ⇒ Object
Returns the value of attribute seat_number.
-
#status ⇒ Object
Returns the value of attribute status.
-
#total_amount ⇒ Object
Returns the value of attribute total_amount.
Instance Method Summary collapse
-
#confirmed? ⇒ Boolean
Returns true if the booking was confirmed successfully.
-
#display_name ⇒ Object
Returns the display name for this booking.
-
#error_message ⇒ Object
Returns the error message if failed.
-
#failed? ⇒ Boolean
Returns true if the booking failed.
-
#from_location ⇒ Object
Returns the from location name.
-
#id ⇒ Object
Returns the booking ID.
-
#initialize(data) ⇒ Booking
constructor
rubocop:disable Lint/MissingSuper.
-
#pending? ⇒ Boolean
Returns true if the booking is pending.
-
#pricing_summary ⇒ Object
Returns pricing summary.
-
#to_h ⇒ Object
Returns a hash representation.
-
#to_location ⇒ Object
Returns the to location name.
Methods inherited from Base
Constructor Details
#initialize(data) ⇒ Booking
rubocop:disable Lint/MissingSuper
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 10 def initialize(data) # rubocop:disable Lint/MissingSuper @booking_code = data['booking_code'] @booking_date = data['booking_date'] @payment_date = data['pay_date'] @booking_status = data['booking_status'] @payment_status = data['payment_status'] @total_amount = data['total_amount'] @currency = data['currency'] @passenger_name = data.dig('customer', 'full_name') @departure_time = data['departure_time'] @arrival_time = data['arrival_time'] @departure_date = data['departure_date'] @seat_number = data['seat_nums'] @bus_type = data['bus_type'] @status = data['status'] @msg = data['msg'] direction = data['direction'] || {} @direction_info = { from_location: direction['from_location'], to_location: direction['to_location'] } end |
Instance Attribute Details
#arrival_time ⇒ Object
Returns the value of attribute arrival_time.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def arrival_time @arrival_time end |
#booking_code ⇒ Object
Returns the value of attribute booking_code.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def booking_code @booking_code end |
#booking_date ⇒ Object
Returns the value of attribute booking_date.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def booking_date @booking_date end |
#booking_status ⇒ Object
Returns the value of attribute booking_status.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def booking_status @booking_status end |
#bus_type ⇒ Object
Returns the value of attribute bus_type.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def bus_type @bus_type end |
#currency ⇒ Object
Returns the value of attribute currency.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def currency @currency end |
#departure_date ⇒ Object
Returns the value of attribute departure_date.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def departure_date @departure_date end |
#departure_time ⇒ Object
Returns the value of attribute departure_time.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def departure_time @departure_time end |
#direction_info ⇒ Object (readonly)
Returns the value of attribute direction_info.
8 9 10 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 8 def direction_info @direction_info end |
#msg ⇒ Object
Returns the value of attribute msg.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def msg @msg end |
#passenger_name ⇒ Object
Returns the value of attribute passenger_name.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def passenger_name @passenger_name end |
#payment_date ⇒ Object
Returns the value of attribute payment_date.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def payment_date @payment_date end |
#payment_status ⇒ Object
Returns the value of attribute payment_status.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def payment_status @payment_status end |
#seat_number ⇒ Object
Returns the value of attribute seat_number.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def seat_number @seat_number end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def status @status end |
#total_amount ⇒ Object
Returns the value of attribute total_amount.
4 5 6 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 4 def total_amount @total_amount end |
Instance Method Details
#confirmed? ⇒ Boolean
Returns true if the booking was confirmed successfully
40 41 42 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 40 def confirmed? booking_status&.include?('Confirmed') && payment_status&.include?('Paid') end |
#display_name ⇒ Object
Returns the display name for this booking
72 73 74 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 72 def display_name "#{passenger_name} - #{booking_code} (#{from_location} → #{to_location})" end |
#error_message ⇒ Object
Returns the error message if failed
55 56 57 58 59 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 55 def return msg if failed? nil end |
#failed? ⇒ Boolean
Returns true if the booking failed
50 51 52 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 50 def failed? !confirmed? && !pending? end |
#from_location ⇒ Object
Returns the from location name
62 63 64 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 62 def from_location direction_info[:from_location] end |
#id ⇒ Object
Returns the booking ID
35 36 37 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 35 def id booking_code end |
#pending? ⇒ Boolean
Returns true if the booking is pending
45 46 47 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 45 def pending? booking_status == 'Pending' || payment_status == 'Unpaid' end |
#pricing_summary ⇒ Object
Returns pricing summary
77 78 79 80 81 82 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 77 def pricing_summary { total_amount: total_amount, currency: currency } end |
#to_h ⇒ Object
Returns a hash representation
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 85 def to_h { id: id, booking_code: booking_code, booking_date: booking_date, payment_date: payment_date, booking_status: booking_status, payment_status: payment_status, confirmed: confirmed?, pending: pending?, failed: failed?, error_message: , total_amount: total_amount, currency: currency, passenger_name: passenger_name, departure_time: departure_time, arrival_time: arrival_time, seat_number: seat_number, bus_type: bus_type, from_location: from_location, to_location: to_location, display_name: display_name, pricing: pricing_summary, status: status, message: msg } end |
#to_location ⇒ Object
Returns the to location name
67 68 69 |
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/booking.rb', line 67 def to_location direction_info[:to_location] end |