Sha256: 43b35c57c3ba6379dd5105a7fb1406c912c268f3d1b6562b2db6acb41342896c
Contents?: true
Size: 826 Bytes
Versions: 1
Compression:
Stored size: 826 Bytes
Contents
# frozen_string_literal: true require 'measured' module Physical class Cuboid attr_reader :dimensions, :width, :height, :depth, :weight, :id, :properties def initialize(id: nil, dimensions: [], dimension_unit: :cm, weight: 0, weight_unit: :g, properties: {}) @id = id || SecureRandom.uuid @weight = Measured::Weight(weight, weight_unit) @dimensions = dimensions.map { |dimension| Measured::Length.new(dimension, dimension_unit) } @dimensions.fill(Measured::Length(self.class::DEFAULT_LENGTH, dimension_unit), @dimensions.length..2) @width, @height, @depth = *@dimensions @properties = properties end def volume Measured::Volume(dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*), :ml) end def ==(other) id == other.id end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
physical-0.1.2 | lib/physical/cuboid.rb |