Class: BoxPacker::Item
Instance Attribute Summary collapse
-
#colour ⇒ Object
readonly
Returns the value of attribute colour.
-
#label ⇒ Object
Returns the value of attribute label.
-
#weight ⇒ Object
Returns the value of attribute weight.
Attributes inherited from Box
Instance Method Summary collapse
-
#initialize(dimensions, opts = {}) ⇒ Item
constructor
A new instance of Item.
- #rotate_to_fit_into(box) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Box
Constructor Details
#initialize(dimensions, opts = {}) ⇒ Item
Returns a new instance of Item.
9 10 11 12 13 14 |
# File 'lib/box_packer/item.rb', line 9 def initialize(dimensions, opts = {}) super(Dimensions[*dimensions]) @label = opts[:label].to_s @weight = opts[:weight] @colour = opts[:colour] || '%06x' % (rand * 0xffffff) end |
Instance Attribute Details
#colour ⇒ Object (readonly)
Returns the value of attribute colour.
7 8 9 |
# File 'lib/box_packer/item.rb', line 7 def colour @colour end |
#label ⇒ Object
Returns the value of attribute label.
6 7 8 |
# File 'lib/box_packer/item.rb', line 6 def label @label end |
#weight ⇒ Object
Returns the value of attribute weight.
6 7 8 |
# File 'lib/box_packer/item.rb', line 6 def weight @weight end |
Instance Method Details
#rotate_to_fit_into(box) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/box_packer/item.rb', line 16 def rotate_to_fit_into(box) each_rotation do |rotation| if box.dimensions >= rotation @dimensions = rotation return true end end false end |
#to_s ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/box_packer/item.rb', line 26 def to_s s = '| Item|' s << " #{label}" if label s << " #{dimensions} #{position} Volume:#{volume}" s << " Weight:#{weight}" if weight s << "\n" end |