Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Resources::Seat
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Integrations::BookMeBusV1::Resources::Seat
- Defined in:
- app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb
Overview
Seat represents a single seat from BookMeBus API
This is a lightweight value object that wraps seat data from the API response. It provides convenience methods for checking seat status and type.
Seat Object Structure from API:
{
"label" => "1", # Seat number/label
"layer" => "BUS", # Layer name
"seat_type" => 0, # 0=regular, 1=vip/sleeper, 2=premium
"status" => 0, # 0=available, 1=booked
"position" => 0, # Absolute position index
"partially_available" => nil,
"gender" => nil # "M", "F", or nil
}
Constant Summary collapse
- TYPE_REGULAR =
Seat type constants
0- TYPE_VIP_SLEEPER =
1- TYPE_PREMIUM =
2- STATUS_AVAILABLE =
Seat status constants
0- STATUS_BOOKED =
1
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#gender ⇒ Object
readonly
Returns the value of attribute gender.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#layer ⇒ Object
readonly
Returns the value of attribute layer.
-
#partially_available ⇒ Object
readonly
Returns the value of attribute partially_available.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#row ⇒ Object
readonly
Returns the value of attribute row.
-
#seat_type ⇒ Object
readonly
Returns the value of attribute seat_type.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#available? ⇒ Boolean
Check if seat is available for booking.
-
#block_type ⇒ Symbol
Get the block type for this seat.
-
#booked? ⇒ Boolean
Check if seat is booked.
-
#initialize(data) ⇒ Seat
constructor
Initialize a seat from BookMeBus seat data.
-
#seat_type_name ⇒ String
Get human-readable seat type name.
Constructor Details
#initialize(data) ⇒ Seat
Initialize a seat from BookMeBus seat data
Example:
seat = Seat.new({
'label' => '1',
'seat_type' => 0,
'status' => 0,
'row' => 0,
'column' => 0
})
46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 46 def initialize(data) @label = data['label'] @layer = data['layer'] @seat_type = data['seat_type'].to_i @status = data['status'].to_i @position = data['position'].to_i @partially_available = data['partially_available'] @gender = data['gender'] @row = data['row'] @column = data['column'] end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def column @column end |
#gender ⇒ Object (readonly)
Returns the value of attribute gender.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def gender @gender end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def label @label end |
#layer ⇒ Object (readonly)
Returns the value of attribute layer.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def layer @layer end |
#partially_available ⇒ Object (readonly)
Returns the value of attribute partially_available.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def partially_available @partially_available end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def position @position end |
#row ⇒ Object (readonly)
Returns the value of attribute row.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def row @row end |
#seat_type ⇒ Object (readonly)
Returns the value of attribute seat_type.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def seat_type @seat_type end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
30 31 32 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 30 def status @status end |
Instance Method Details
#available? ⇒ Boolean
69 70 71 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 69 def available? status == STATUS_AVAILABLE end |
#block_type ⇒ Symbol
99 100 101 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 99 def block_type seat_type == TYPE_VIP_SLEEPER ? :sleeping_seat : :seat end |
#booked? ⇒ Boolean
84 85 86 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 84 def booked? status != STATUS_AVAILABLE end |
#seat_type_name ⇒ String
117 118 119 120 121 122 123 124 |
# File 'app/services/spree_cm_commissioner/integrations/book_me_bus_v1/resources/seat.rb', line 117 def seat_type_name case seat_type when TYPE_REGULAR then 'regular' when TYPE_VIP_SLEEPER then 'vip' when TYPE_PREMIUM then 'premium' else 'unknown' end end |