Class: SpreeCmCommissioner::Integrations::VireakBuntham::Resources::SeatLayout
- Inherits:
-
Base
- Object
- Base
- SpreeCmCommissioner::Integrations::VireakBuntham::Resources::SeatLayout
- Defined in:
- app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb
Overview
Wraps a VET seat layout returned by POST /seat/layout.
VET’s response shape:
{
"header": { ... },
"body": [
{ "layout": "<JSON string of rows>" }
]
}
The ‘layout` field is a JSON-encoded string of rows. Each row has `col` entries with `value` (internal seat id), `label` (display label), and `attr.colspan/rowspan` for merged cells (Toilet, Door, Capitain, etc.).
Instance Attribute Summary collapse
-
#raw_layout ⇒ Object
Returns the value of attribute raw_layout.
-
#rows ⇒ Object
Returns the value of attribute rows.
Instance Method Summary collapse
-
#all_cells ⇒ Object
Returns ALL non-nil, non-empty cells — bookable and non-bookable alike.
- #column_count ⇒ Object
-
#initialize(data) ⇒ SeatLayout
constructor
rubocop:disable Lint/MissingSuper.
- #row_count ⇒ Object
-
#seats ⇒ Object
Returns flat array of bookable seat cells only.
- #to_h ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(data) ⇒ SeatLayout
rubocop:disable Lint/MissingSuper
18 19 20 21 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 18 def initialize(data) # rubocop:disable Lint/MissingSuper @raw_layout = data['layout'] @rows = parse_rows(@raw_layout) end |
Instance Attribute Details
#raw_layout ⇒ Object
Returns the value of attribute raw_layout.
16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 16 def raw_layout @raw_layout end |
#rows ⇒ Object
Returns the value of attribute rows.
16 17 18 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 16 def rows @rows end |
Instance Method Details
#all_cells ⇒ Object
Returns ALL non-nil, non-empty cells — bookable and non-bookable alike. Used by SyncSeatLayout to create :text blocks for stairs/dividers.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 31 def all_cells cells = [] rows.each_with_index do |row, row_idx| Array(row['col']).each_with_index do |cell, col_idx| next if cell.nil? next if cell['label'].to_s.strip.empty? cells << Cell.new( value: cell['value'], label: cell['label'].to_s, row: row_idx, col: col_idx, colspan: cell.dig('attr', 'colspan').to_i.then { |n| n.positive? ? n : 1 }, rowspan: cell.dig('attr', 'rowspan').to_i.then { |n| n.positive? ? n : 1 } ) end end cells end |
#column_count ⇒ Object
55 56 57 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 55 def column_count rows.map { |row| Array(row['col']).size }.max || 0 end |
#row_count ⇒ Object
51 52 53 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 51 def row_count rows.size end |
#seats ⇒ Object
Returns flat array of bookable seat cells only. Skips non-bookable cells (empty labels, Toilet, Door, Stair, etc.).
25 26 27 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 25 def seats all_cells.select(&:bookable?) end |
#to_h ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/services/spree_cm_commissioner/integrations/vireak_buntham/resources/seat_layout.rb', line 59 def to_h { rows: rows, seat_count: seats.size, row_count: row_count, column_count: column_count } end |