Class: BoxPacker::Box
- Inherits:
-
Object
- Object
- BoxPacker::Box
- Extended by:
- Forwardable
- Defined in:
- lib/box_packer/box.rb
Instance Attribute Summary collapse
-
#dimensions ⇒ Object
Returns the value of attribute dimensions.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
- #>=(other) ⇒ Object
-
#initialize(dimensions, opts = {}) ⇒ Box
constructor
A new instance of Box.
- #orient! ⇒ Object
- #sub_boxes(item) ⇒ Object
Constructor Details
#initialize(dimensions, opts = {}) ⇒ Box
Returns a new instance of Box.
9 10 11 12 |
# File 'lib/box_packer/box.rb', line 9 def initialize(dimensions, opts = {}) @dimensions = dimensions @position = opts[:position] || Position[0, 0, 0] end |
Instance Attribute Details
#dimensions ⇒ Object
Returns the value of attribute dimensions.
15 16 17 |
# File 'lib/box_packer/box.rb', line 15 def dimensions @dimensions end |
#position ⇒ Object
Returns the value of attribute position.
15 16 17 |
# File 'lib/box_packer/box.rb', line 15 def position @position end |
Instance Method Details
#>=(other) ⇒ Object
21 22 23 |
# File 'lib/box_packer/box.rb', line 21 def >=(other) dimensions >= other.dimensions end |
#orient! ⇒ Object
17 18 19 |
# File 'lib/box_packer/box.rb', line 17 def orient! @dimensions = Dimensions[*dimensions.to_a.sort!.reverse!] end |
#sub_boxes(item) ⇒ Object
25 26 27 28 29 |
# File 'lib/box_packer/box.rb', line 25 def sub_boxes(item) sub_boxes = sub_boxes_args(item).select { |(d, _)| d.volume > 0 } sub_boxes.map! { |args| Box.new(*args) } sub_boxes.sort_by!(&:volume).reverse! end |