Class: SpreeCmCommissioner::Integrations::Larryta::Resources::SeatAvailability

Inherits:
Base
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb

Overview

Represents seat availability response from Larryta API

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_api_response

Constructor Details

#initialize(data) ⇒ SeatAvailability

rubocop:disable Lint/MissingSuper



7
8
9
10
11
12
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 7

def initialize(data) # rubocop:disable Lint/MissingSuper
  @total_seats = data['total_seat']
  @seat_numbers = data['seat_nums']
  @status = data['status']
  @msg = data['msg']
end

Instance Attribute Details

#msgObject (readonly)

Returns the value of attribute msg.



5
6
7
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 5

def msg
  @msg
end

#seat_numbersObject

Returns the value of attribute seat_numbers.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 4

def seat_numbers
  @seat_numbers
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 5

def status
  @status
end

#total_seatsObject

Returns the value of attribute total_seats.



4
5
6
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 4

def total_seats
  @total_seats
end

Instance Method Details

#available?Boolean

Returns true if seats are available

Returns:

  • (Boolean)


22
23
24
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 22

def available?
  status == true && total_seats.to_i.positive?
end

#countObject

Returns the count of available seats



32
33
34
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 32

def count
  total_seats
end

#fully_booked?Boolean

Returns true if no seats are available

Returns:

  • (Boolean)


27
28
29
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 27

def fully_booked?
  total_seats.to_i.zero?
end

#seat_listObject

Returns array of seat numbers



15
16
17
18
19
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 15

def seat_list
  return [] if seat_numbers.blank?

  seat_numbers.split(',').map(&:to_i).sort
end

#to_hObject

Returns a hash representation



37
38
39
40
41
42
43
44
45
46
47
# File 'app/services/spree_cm_commissioner/integrations/larryta/resources/seat_availability.rb', line 37

def to_h
  {
    total_seats: total_seats,
    seat_numbers: seat_list,
    count: count,
    available: available?,
    fully_booked: fully_booked?,
    status: status,
    message: msg
  }
end