Class: Physical::Cuboid
- Inherits:
-
Object
- Object
- Physical::Cuboid
- Defined in:
- lib/physical/cuboid.rb
Instance Attribute Summary collapse
-
#dimensions ⇒ Object
readonly
Returns the value of attribute dimensions.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(id: nil, dimensions: [], weight: Measured::Weight(0, :g), properties: {}) ⇒ Cuboid
constructor
A new instance of Cuboid.
- #volume ⇒ Object
Constructor Details
#initialize(id: nil, dimensions: [], weight: Measured::Weight(0, :g), properties: {}) ⇒ Cuboid
Returns a new instance of Cuboid.
9 10 11 12 13 14 15 16 |
# File 'lib/physical/cuboid.rb', line 9 def initialize(id: nil, dimensions: [], weight: Measured::Weight(0, :g), properties: {}) @id = id || SecureRandom.uuid @weight = Types::Weight[weight] @dimensions = [] @dimensions = fill_dimensions(Types::Dimensions[dimensions]) @length, @width, @height = *@dimensions @properties = properties end |
Instance Attribute Details
#dimensions ⇒ Object (readonly)
Returns the value of attribute dimensions.
7 8 9 |
# File 'lib/physical/cuboid.rb', line 7 def dimensions @dimensions end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
7 8 9 |
# File 'lib/physical/cuboid.rb', line 7 def height @height end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/physical/cuboid.rb', line 7 def id @id end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
7 8 9 |
# File 'lib/physical/cuboid.rb', line 7 def length @length end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
7 8 9 |
# File 'lib/physical/cuboid.rb', line 7 def properties @properties end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
7 8 9 |
# File 'lib/physical/cuboid.rb', line 7 def weight @weight end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
7 8 9 |
# File 'lib/physical/cuboid.rb', line 7 def width @width end |
Instance Method Details
#==(other) ⇒ Object
22 23 24 |
# File 'lib/physical/cuboid.rb', line 22 def ==(other) id == other.id end |
#volume ⇒ Object
18 19 20 |
# File 'lib/physical/cuboid.rb', line 18 def volume Measured::Volume(dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*), :ml) end |