lib/physical/package.rb in physical-0.4.4 vs lib/physical/package.rb in physical-0.4.5
- old
+ new
@@ -12,36 +12,47 @@
@items = Set[*items]
end
delegate [:dimensions, :width, :length, :height, :properties, :volume] => :container
- def <<(item)
- @items.add(item)
+ def <<(other)
+ @items.add(other)
end
alias_method :add, :<<
- def >>(item)
- @items.delete(item)
+ def >>(other)
+ @items.delete(other)
end
alias_method :delete, :>>
def weight
- container.weight + items.map(&:weight).reduce(Measured::Weight(0, :g), &:+) + void_fill_weight
+ container.weight + items_weight + void_fill_weight
end
- def remaining_volume
- container.inner_volume - items.map(&:volume).reduce(Measured::Volume(0, :ml), &:+)
+ # @return [Measured::Weight]
+ def items_weight
+ items.map(&:weight).reduce(Measured::Weight(0, :g), &:+)
end
def void_fill_weight
return Measured::Weight(0, :g) if container.volume.value.infinite?
Measured::Weight(void_fill_density.convert_to(:g_ml).value * remaining_volume.convert_to(:ml).value, :g)
end
+ # @return [Measured::Volume]
+ def used_volume
+ items.map(&:volume).reduce(Measured::Volume(0, :ml), &:+)
+ end
+
+ def remaining_volume
+ container.inner_volume - used_volume
+ end
+
def density
return Measured::Density(Float::INFINITY, :g_ml) if container.volume.value.zero?
return Measured::Density(0.0, :g_ml) if container.volume.value.infinite?
+
Measured::Density(weight.convert_to(:g).value / container.volume.convert_to(:ml).value, :g_ml)
end
end
end