Class: Physical::Box
Constant Summary collapse
- DEFAULT_LENGTH =
BigDecimal::INFINITY
- DEFAULT_MAX_WEIGHT =
BigDecimal::INFINITY
Instance Attribute Summary collapse
-
#inner_dimensions ⇒ Object
readonly
Returns the value of attribute inner_dimensions.
-
#inner_height ⇒ Object
readonly
Returns the value of attribute inner_height.
-
#inner_length ⇒ Object
readonly
Returns the value of attribute inner_length.
-
#inner_width ⇒ Object
readonly
Returns the value of attribute inner_width.
-
#max_weight ⇒ Object
readonly
Returns the value of attribute max_weight.
Attributes inherited from Cuboid
#dimensions, #height, #id, #length, #properties, #weight, #width
Instance Method Summary collapse
-
#initialize(**args) ⇒ Box
constructor
A new instance of Box.
- #inner_volume ⇒ Object
- #item_fits?(item) ⇒ Boolean
Methods inherited from Cuboid
Constructor Details
#initialize(**args) ⇒ Box
Returns a new instance of Box.
16 17 18 19 20 21 22 23 |
# File 'lib/physical/box.rb', line 16 def initialize(**args) inner_dimensions = args.delete(:inner_dimensions) || [] max_weight = args.delete(:max_weight) || Measured::Weight(DEFAULT_MAX_WEIGHT, :g) super(**args) @inner_dimensions = fill_dimensions(Types::Dimensions[inner_dimensions]) @inner_length, @inner_width, @inner_height = *@inner_dimensions @max_weight = Types::Weight[max_weight] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Physical::PropertyReaders
Instance Attribute Details
#inner_dimensions ⇒ Object (readonly)
Returns the value of attribute inner_dimensions.
10 11 12 |
# File 'lib/physical/box.rb', line 10 def inner_dimensions @inner_dimensions end |
#inner_height ⇒ Object (readonly)
Returns the value of attribute inner_height.
10 11 12 |
# File 'lib/physical/box.rb', line 10 def inner_height @inner_height end |
#inner_length ⇒ Object (readonly)
Returns the value of attribute inner_length.
10 11 12 |
# File 'lib/physical/box.rb', line 10 def inner_length @inner_length end |
#inner_width ⇒ Object (readonly)
Returns the value of attribute inner_width.
10 11 12 |
# File 'lib/physical/box.rb', line 10 def inner_width @inner_width end |
#max_weight ⇒ Object (readonly)
Returns the value of attribute max_weight.
10 11 12 |
# File 'lib/physical/box.rb', line 10 def max_weight @max_weight end |
Instance Method Details
#inner_volume ⇒ Object
25 26 27 28 29 30 |
# File 'lib/physical/box.rb', line 25 def inner_volume Measured::Volume( inner_dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*), :ml ) end |
#item_fits?(item) ⇒ Boolean
34 35 36 37 38 39 40 41 42 |
# File 'lib/physical/box.rb', line 34 def item_fits?(item) return false if item.weight > max_weight box_dimensions = inner_dimensions.sort item.dimensions.sort.each.with_index do |axis, index| return false if axis >= box_dimensions[index] end true end |