class Boxify::EligibleBox
Attributes
boxes[R]
space[R]
Public Class Methods
find_all(boxes:, space:)
click to toggle source
# File lib/boxify/eligible_box.rb, line 11 def self.find_all(boxes:, space:) new(boxes: boxes, space: space).eligible_boxes end
find_best_fit(boxes:, space:)
click to toggle source
# File lib/boxify/eligible_box.rb, line 15 def self.find_best_fit(boxes:, space:) new(boxes: boxes, space: space).eligible_box_with_largest_volume end
new(boxes:, space:)
click to toggle source
# File lib/boxify/eligible_box.rb, line 6 def initialize(boxes:, space:) @boxes = boxes @space = space end
Public Instance Methods
eligible_box_with_largest_volume()
click to toggle source
# File lib/boxify/eligible_box.rb, line 23 def eligible_box_with_largest_volume @eligible_box_with_largest_volume ||= find_box_with_largest_volume(eligible_boxes) end
eligible_boxes()
click to toggle source
# File lib/boxify/eligible_box.rb, line 19 def eligible_boxes @eligible_boxes ||= find_eligible_boxes end
Private Instance Methods
find_box_with_largest_volume(boxes)
click to toggle source
# File lib/boxify/eligible_box.rb, line 42 def find_box_with_largest_volume(boxes) if boxes.size > 1 # Return box with largest volume boxes.sort{ |b| b.volume }.first else boxes.first end end
find_eligible_boxes()
click to toggle source
# File lib/boxify/eligible_box.rb, line 29 def find_eligible_boxes da_boxes = boxes.select do |box| true if (box.width <= space.width) && (box.height <= space.height) rotated_copy = box.rotated if (rotated_copy.width <= space.width) && (rotated_copy.height <= space.height) box.rotate true end end da_boxes end