physical 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -3
- data/lib/physical/box.rb +1 -6
- data/lib/physical/cuboid.rb +2 -7
- data/lib/physical/package.rb +1 -1
- data/lib/physical/spec_support/shared_examples.rb +8 -12
- data/lib/physical/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 686fa9f5c3c2f0730b7b48eb0ad8260efc421068
|
4
|
+
data.tar.gz: c1cb821fdf67cfed55be6fff0868d84fc9edc563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ddf78ab2078a8a05229ac80fd6d8aded0d8be0ad81a5300662c93f013351331ff4a2aaaffc1f659fc3a79162b66c11762b150e881890dec5ea9ca94e2d0f228
|
7
|
+
data.tar.gz: 608a2c01f153f33dffa3373ad81f15724b34e4c33f79f968d0e804a3d0499b272fbba379a5511e95d35b855773f0f71e9db782e50145063bf06bda3f8d4794e0
|
data/README.md
CHANGED
@@ -52,9 +52,7 @@ You will be able to retrieve the package's weight and dimensions using the `#wei
|
|
52
52
|
|
53
53
|
### Convenience methods
|
54
54
|
|
55
|
-
The length, width and height of a package are defined as the
|
56
|
-
|
57
|
-
The package's `length` is also accessible as `package.x`. The package's `width` is also accessible as `package.y`. The package's `height` is also accessible as `package.z` as well as `package.depth`.
|
55
|
+
The length, width and height of a package are defined as the dimension array's first, second, and third argument, respectively. For the package from the previous example, `package.length` will be 3 inches, `package.width` will be 4 inches, and `package.height` will be 5 inches.
|
58
56
|
|
59
57
|
### Packages with Items
|
60
58
|
|
data/lib/physical/box.rb
CHANGED
@@ -13,14 +13,9 @@ module Physical
|
|
13
13
|
def initialize(inner_dimensions: [], **args)
|
14
14
|
super args
|
15
15
|
@inner_dimensions = fill_dimensions(Types::Dimensions[inner_dimensions])
|
16
|
-
@inner_length, @inner_width, @inner_height = *@inner_dimensions
|
16
|
+
@inner_length, @inner_width, @inner_height = *@inner_dimensions
|
17
17
|
end
|
18
18
|
|
19
|
-
alias :inner_x :inner_length
|
20
|
-
alias :inner_y :inner_width
|
21
|
-
alias :inner_z :inner_height
|
22
|
-
alias :inner_depth :inner_height
|
23
|
-
|
24
19
|
def inner_volume
|
25
20
|
Measured::Volume(
|
26
21
|
inner_dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*),
|
data/lib/physical/cuboid.rb
CHANGED
@@ -11,15 +11,10 @@ module Physical
|
|
11
11
|
@weight = Types::Weight[weight]
|
12
12
|
@dimensions = []
|
13
13
|
@dimensions = fill_dimensions(Types::Dimensions[dimensions])
|
14
|
-
@length, @width, @height = *@dimensions
|
14
|
+
@length, @width, @height = *@dimensions
|
15
15
|
@properties = properties
|
16
16
|
end
|
17
17
|
|
18
|
-
alias :x :length
|
19
|
-
alias :y :width
|
20
|
-
alias :z :height
|
21
|
-
alias :depth :height
|
22
|
-
|
23
18
|
def volume
|
24
19
|
Measured::Volume(dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*), :ml)
|
25
20
|
end
|
@@ -33,7 +28,7 @@ module Physical
|
|
33
28
|
def fill_dimensions(dimensions)
|
34
29
|
dimensions.fill(dimensions.length..2) do |index|
|
35
30
|
@dimensions[index] || Measured::Length(self.class::DEFAULT_LENGTH, :cm)
|
36
|
-
end
|
31
|
+
end
|
37
32
|
end
|
38
33
|
end
|
39
34
|
end
|
data/lib/physical/package.rb
CHANGED
@@ -12,7 +12,7 @@ module Physical
|
|
12
12
|
@items = Set[*items]
|
13
13
|
end
|
14
14
|
|
15
|
-
delegate [:dimensions, :width, :length, :height, :
|
15
|
+
delegate [:dimensions, :width, :length, :height, :properties] => :container
|
16
16
|
|
17
17
|
def <<(item)
|
18
18
|
@items.add(item)
|
@@ -5,9 +5,9 @@ RSpec.shared_examples 'a cuboid' do
|
|
5
5
|
{
|
6
6
|
dimensions: [
|
7
7
|
Measured::Length.new(1.1, :cm),
|
8
|
-
Measured::Length.new(
|
9
|
-
Measured::Length.new(
|
10
|
-
]
|
8
|
+
Measured::Length.new(3.3, :cm),
|
9
|
+
Measured::Length.new(2.2, :cm)
|
10
|
+
]
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
@@ -17,19 +17,15 @@ RSpec.shared_examples 'a cuboid' do
|
|
17
17
|
expect(subject.dimensions).to eq(
|
18
18
|
[
|
19
19
|
Measured::Length.new(1.1, :cm),
|
20
|
-
Measured::Length.new(
|
21
|
-
Measured::Length.new(
|
20
|
+
Measured::Length.new(3.3, :cm),
|
21
|
+
Measured::Length.new(2.2, :cm)
|
22
22
|
]
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "has getter methods for each dimension as Measured::Length object" do
|
27
|
-
expect(subject.length).to eq(Measured::Length.new(
|
28
|
-
expect(subject.
|
29
|
-
expect(subject.
|
30
|
-
expect(subject.y).to eq(Measured::Length.new(2.2, :cm))
|
31
|
-
expect(subject.height).to eq(Measured::Length.new(1.1, :cm))
|
32
|
-
expect(subject.z).to eq(Measured::Length.new(1.1, :cm))
|
33
|
-
expect(subject.depth).to eq(Measured::Length.new(1.1, :cm))
|
27
|
+
expect(subject.length).to eq(Measured::Length.new(1.1, :cm))
|
28
|
+
expect(subject.width).to eq(Measured::Length.new(3.3, :cm))
|
29
|
+
expect(subject.height).to eq(Measured::Length.new(2.2, :cm))
|
34
30
|
end
|
35
31
|
end
|
data/lib/physical/version.rb
CHANGED