Sha256: 80d8824aa1f290846a743288e882aab2c678392bc0d76b69bff3c1d21fe2d0ce

Contents?: true

Size: 817 Bytes

Versions: 4

Compression:

Stored size: 817 Bytes

Contents

# frozen_string_literal: true

require 'measured'

module Physical
  class Box < Cuboid
    DEFAULT_LENGTH = BigDecimal::INFINITY
    DEFAULT_MAX_WEIGHT = BigDecimal::INFINITY

    attr_reader :inner_dimensions,
                :inner_length,
                :inner_width,
                :inner_height,
                :max_weight

    def initialize(inner_dimensions: [], max_weight: Measured::Weight(DEFAULT_MAX_WEIGHT, :g), **args)
      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

    def inner_volume
      Measured::Volume(
        inner_dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*),
        :ml
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
physical-0.4.4 lib/physical/box.rb
physical-0.4.3 lib/physical/box.rb
physical-0.4.2 lib/physical/box.rb
physical-0.4.1 lib/physical/box.rb