Class: SpreeCmCommissioner::Integrations::VireakBuntham::Resources::Cell

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb

Overview

Wraps a single cell from VET’s seat layout grid.

Provides two key capabilities:

1. Classify the cell's block_type (:seat, :driver, :bathroom, :other, :text)
   based on its label using a single LABEL_BLOCK_TYPE_MAP
2. Determine if the cell is bookable via Block.sellable?

This value object is the single source of truth for label → block_type mapping. Add new VET label types here; no need to change the sync service.

Constant Summary collapse

LABEL_BLOCK_TYPE_MAP =

Single source of truth: maps a downcased label substring → block_type. The map is checked via substring matching (include?) on the lowercased label. This allows a single entry to cover variants: ‘open’ covers Open, Open2, Open5.

{
  'driver' => :driver,
  'toilet' => :bathroom,
  'capitain' => :bathroom,
  'captain' => :bathroom,
  'door' => :other,
  'hostess' => :other,
  'open' => :other,   # covers Open, Open2, Open5
  'stair' => :text    # covers Stair, UpStair, DownStair
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Cell

Returns a new instance of Cell.



28
29
30
31
32
33
34
35
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 28

def initialize(data)
  @value   = data[:value]
  @label   = data[:label].to_s
  @row     = data[:row]
  @col     = data[:col]
  @colspan = data[:colspan]
  @rowspan = data[:rowspan]
end

Instance Attribute Details

#colObject (readonly)

Returns the value of attribute col.



26
27
28
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 26

def col
  @col
end

#colspanObject (readonly)

Returns the value of attribute colspan.



26
27
28
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 26

def colspan
  @colspan
end

#labelObject (readonly)

Returns the value of attribute label.



26
27
28
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 26

def label
  @label
end

#rowObject (readonly)

Returns the value of attribute row.



26
27
28
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 26

def row
  @row
end

#rowspanObject (readonly)

Returns the value of attribute rowspan.



26
27
28
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 26

def rowspan
  @rowspan
end

#valueObject (readonly)

Returns the value of attribute value.



26
27
28
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 26

def value
  @value
end

Instance Method Details

#block_typeObject

Determine the block_type for this cell. Searches LABEL_BLOCK_TYPE_MAP for a substring match (case-insensitive). Falls back to :seat for unknown labels (safe: anything not explicitly mapped is treated as a regular bookable seat).



41
42
43
44
45
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 41

def block_type
  downcased = label.downcase
  _, type = LABEL_BLOCK_TYPE_MAP.find { |keyword, _| downcased.include?(keyword) }
  type || :seat
end

#bookable?Boolean

Determine if this cell represents a bookable element. Delegates to Block.sellable? — the authoritative definition of “can be sold”.

Returns:

  • (Boolean)


49
50
51
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/cell.rb', line 49

def bookable?
  SpreeCmCommissioner::Block.sellable?(block_type)
end