Class: GeneralUnits::Box::Packer

Inherits:
Object
  • Object
show all
Defined in:
lib/general_units/derivatives/box/packer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*boxes) ⇒ Packer

Returns a new instance of Packer.



7
8
9
10
11
12
13
14
# File 'lib/general_units/derivatives/box/packer.rb', line 7

def initialize(*boxes)
  @boxes = boxes.sort_by(&:max_face).reverse
  @coupled = @boxes.first # first box - biggest
  @gaps = []
  @gaps_used = [] # for test
  @rotated = 0 # if height > current length
  pack!
end

Instance Attribute Details

#boxesObject (readonly)

Returns the value of attribute boxes.



5
6
7
# File 'lib/general_units/derivatives/box/packer.rb', line 5

def boxes
  @boxes
end

#coupledObject (readonly)

Returns the value of attribute coupled.



5
6
7
# File 'lib/general_units/derivatives/box/packer.rb', line 5

def coupled
  @coupled
end

#gapsObject (readonly)

Returns the value of attribute gaps.



5
6
7
# File 'lib/general_units/derivatives/box/packer.rb', line 5

def gaps
  @gaps
end

#gaps_usedObject (readonly)

Returns the value of attribute gaps_used.



5
6
7
# File 'lib/general_units/derivatives/box/packer.rb', line 5

def gaps_used
  @gaps_used
end

#rotatedObject (readonly)

Returns the value of attribute rotated.



5
6
7
# File 'lib/general_units/derivatives/box/packer.rb', line 5

def rotated
  @rotated
end

Instance Method Details

#inspectObject



20
21
22
# File 'lib/general_units/derivatives/box/packer.rb', line 20

def inspect
  "<#{self.class.name} boxes=#{boxes.size} gaps=#{gaps.size} used=#{gaps_used.size} coupled=#{coupled}>"
end

#to_sObject



16
17
18
# File 'lib/general_units/derivatives/box/packer.rb', line 16

def to_s
  inspect
end