Class: SpreeCmCommissioner::VehicleType
- Includes:
- RouteType
- Defined in:
- app/models/spree_cm_commissioner/vehicle_type.rb
Constant Summary
Constants included from RouteType
Instance Method Summary collapse
- #after_activate ⇒ Object
- #after_archive ⇒ Object
- #after_draft ⇒ Object
- #recalculate_vehicle_seats_count ⇒ Object
- #seat_layers ⇒ Object
- #set_vehicles_attributes ⇒ Object
Instance Method Details
#after_activate ⇒ Object
39 |
# File 'app/models/spree_cm_commissioner/vehicle_type.rb', line 39 def after_activate; end |
#after_archive ⇒ Object
40 |
# File 'app/models/spree_cm_commissioner/vehicle_type.rb', line 40 def after_archive; end |
#after_draft ⇒ Object
41 |
# File 'app/models/spree_cm_commissioner/vehicle_type.rb', line 41 def after_draft; end |
#recalculate_vehicle_seats_count ⇒ Object
48 49 50 51 |
# File 'app/models/spree_cm_commissioner/vehicle_type.rb', line 48 def recalculate_vehicle_seats_count self.vehicle_seats_count = vehicle_seats.where(seat_type: %w[normal vip]).count save end |
#seat_layers ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/spree_cm_commissioner/vehicle_type.rb', line 53 def seat_layers grouped_seats = SpreeCmCommissioner::VehicleSeat.where(vehicle_type_id: id).group_by(&:layer).transform_values do |seats| seats.group_by(&:row).transform_values do |row_seats| row_seats.sort_by(&:column).map do |seat| { row: seat.row, column: seat.column, label: seat.label, layer: seat.layer, seat_type: seat.seat_type, created_at: seat.created_at, vehicle_type_id: seat.vehicle_type_id } end end end grouped_seats.map do |_layer, layer_seats| layer_seats.map do |_row, row_seats| row_seats end end end |
#set_vehicles_attributes ⇒ Object
43 44 45 46 |
# File 'app/models/spree_cm_commissioner/vehicle_type.rb', line 43 def set_vehicles_attributes vehicles.each(&:set_attributes) vehicles.each(&:save) end |