Class: SpaceCalculator::LocationPacker::Pile

Inherits:
Object
  • Object
show all
Defined in:
backend/app/model/space_calculator.rb

Instance Method Summary collapse

Constructor Details

#initialize(location_dims) ⇒ Pile

Returns a new instance of Pile.



280
281
282
283
# File 'backend/app/model/space_calculator.rb', line 280

def initialize(location_dims)
  @location_dims = location_dims
  @containers = []
end

Instance Method Details

#add(container) ⇒ Object



286
287
288
# File 'backend/app/model/space_calculator.rb', line 286

def add(container)
  @containers << container
end

#containers_per_towerObject



315
316
317
318
319
320
321
322
323
324
325
# File 'backend/app/model/space_calculator.rb', line 315

def containers_per_tower
  container = @containers[0]
  number_that_fit = (@location_dims.height / container.dimensions.height).to_i

  # If there's a limit on how high we can stack these, cap it.
  if container.max_tower_count != :unlimited
    number_that_fit = [number_that_fit, container.max_tower_count].min
  end

  number_that_fit
end

#depthObject



301
302
303
# File 'backend/app/model/space_calculator.rb', line 301

def depth
  @containers[0].dimensions.depth
end

#heightObject



296
297
298
# File 'backend/app/model/space_calculator.rb', line 296

def height
  @containers[0].dimensions.height
end

#max_container_countObject



328
329
330
331
332
# File 'backend/app/model/space_calculator.rb', line 328

def max_container_count
  number_of_towers = (@location_dims.depth / @containers[0].dimensions.depth).to_i

  containers_per_tower * number_of_towers
end

#widthObject



291
292
293
# File 'backend/app/model/space_calculator.rb', line 291

def width
  @containers[0].dimensions.width
end

#will_fit(container) ⇒ Object



306
307
308
309
310
311
312
# File 'backend/app/model/space_calculator.rb', line 306

def will_fit(container)
  if @containers.length > 0 && @containers[0].name != container.name
    return false
  end

  @containers.length < max_container_count
end