Class: BoxPacker::Packing
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- BoxPacker::Packing
- Defined in:
- lib/box_packer/packing.rb
Instance Attribute Summary collapse
-
#remaining_volume ⇒ Object
readonly
Returns the value of attribute remaining_volume.
-
#remaining_weight ⇒ Object
readonly
Returns the value of attribute remaining_weight.
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #fit?(item) ⇒ Boolean
-
#initialize(total_volume, total_weight) ⇒ Packing
constructor
A new instance of Packing.
- #to_s ⇒ Object
Constructor Details
#initialize(total_volume, total_weight) ⇒ Packing
Returns a new instance of Packing.
7 8 9 10 11 |
# File 'lib/box_packer/packing.rb', line 7 def initialize(total_volume, total_weight) super([]) @remaining_volume = total_volume @remaining_weight = total_weight end |
Instance Attribute Details
#remaining_volume ⇒ Object (readonly)
Returns the value of attribute remaining_volume.
5 6 7 |
# File 'lib/box_packer/packing.rb', line 5 def remaining_volume @remaining_volume end |
#remaining_weight ⇒ Object (readonly)
Returns the value of attribute remaining_weight.
5 6 7 |
# File 'lib/box_packer/packing.rb', line 5 def remaining_weight @remaining_weight end |
Instance Method Details
#<<(item) ⇒ Object
13 14 15 16 17 |
# File 'lib/box_packer/packing.rb', line 13 def <<(item) @remaining_volume -= item.volume @remaining_weight -= item.weight if weight?(item) super end |
#fit?(item) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/box_packer/packing.rb', line 19 def fit?(item) return false if include?(item) return false if remaining_volume < item.volume return false if weight?(item) && remaining_weight < item.weight true end |
#to_s ⇒ Object
26 27 28 29 30 31 |
# File 'lib/box_packer/packing.rb', line 26 def to_s s = "| Packing| Remaining Volume:#{remaining_volume}" s << " Remaining Weight:#{remaining_weight}" if remaining_weight s << "\n" s << map(&:to_s).join end |