Class: SpreeCmCommissioner::Integrations::BookMeBusV1::Resources::Seat

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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
})

Parameters:

  • data (Hash)

    Seat data from API with row/column added



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

#columnObject (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

#genderObject (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

#labelObject (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

#layerObject (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_availableObject (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

#positionObject (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

#rowObject (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_typeObject (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

#statusObject (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

Check if seat is available for booking

Example:

seat = Seat.new({'status' => 0})
seat.available?  # => true

seat = Seat.new({'status' => 1})
seat.available?  # => false

Returns:

  • (Boolean)

    true if status is 0 (available)



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_typeSymbol

Get the block type for this seat

Example:

seat = Seat.new({'seat_type' => 0})
seat.block_type  # => :seat

seat = Seat.new({'seat_type' => 1})
seat.block_type  # => :sleeping_seat

Returns:

  • (Symbol)

    Block type (:seat or :sleeping_seat)



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

Check if seat is booked

Example:

seat = Seat.new({'status' => 1})
seat.booked?  # => true

seat = Seat.new({'status' => 0})
seat.booked?  # => false

Returns:

  • (Boolean)

    true if status is not 0 (booked)



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_nameString

Get human-readable seat type name

Example:

seat = Seat.new({'seat_type' => 0})
seat.seat_type_name  # => "regular"

seat = Seat.new({'seat_type' => 1})
seat.seat_type_name  # => "vip"

seat = Seat.new({'seat_type' => 2})
seat.seat_type_name  # => "premium"

Returns:

  • (String)

    Seat type name



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