physical 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/measured/density.rb +28 -0
- data/lib/physical.rb +1 -0
- data/lib/physical/cuboid.rb +6 -0
- data/lib/physical/package.rb +10 -4
- data/lib/physical/spec_support/factories/box_factory.rb +1 -1
- data/lib/physical/spec_support/factories/package_factory.rb +1 -1
- data/lib/physical/types.rb +1 -0
- data/lib/physical/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69552008d60146d8d2aff0d47ae732a1baf06d3f
|
4
|
+
data.tar.gz: 4bdd77b725a51cf6aa989ddf34ca4b08fc92e5f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02e59b75eab848337c424e2c941a752d3328235987f65e031330de022cd50e04b41db8f5488c31bc614a0374e10627478b87a93db2e697f6b8319e633f25372c
|
7
|
+
data.tar.gz: eb257f74a3353fed64edf7579043e8dcf76a2d52b35653201841d05d091f528cbd66abd1faf4d2c5207557eb66c8e193c513aa6dbdaf47cabf30eec43b252849
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
|
9
|
+
## [0.4.0] - 2019-07-10
|
10
|
+
### Added
|
11
|
+
- `Measured::Density` Type and density calculations [@tvdeyen](https://github.com/mamhoff/physical/pull/19)
|
12
|
+
- Use `Measured::Density` Type when initializing `Physical::Package#void_fill_density` [@mamhoff](https://github.com/mamhoff/physical/pull/22)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'measured'
|
4
|
+
|
5
|
+
Measured::Density = Measured.build do
|
6
|
+
si_unit :kg_m3, aliases: [
|
7
|
+
:kilogram_per_cubic_meter,
|
8
|
+
:kilogram_per_cubic_metre,
|
9
|
+
:kilograms_per_cubic_meter,
|
10
|
+
:kilograms_per_cubic_metre
|
11
|
+
]
|
12
|
+
|
13
|
+
unit :g_ml, aliases: [
|
14
|
+
:gram_per_milliliter,
|
15
|
+
:gram_per_millilitre,
|
16
|
+
:grams_per_milliliter,
|
17
|
+
:grams_per_millilitre
|
18
|
+
], value: '1000 kg_m3'
|
19
|
+
|
20
|
+
# UPS Freight classes use pound per cubic feet as density unit
|
21
|
+
unit :lb_ft3, aliases: [
|
22
|
+
:lbs_ft3,
|
23
|
+
:pound_per_cubiq_foot,
|
24
|
+
:pound_per_cubiq_feet,
|
25
|
+
:pounds_per_cubiq_foot,
|
26
|
+
:pounds_per_cubiq_feet
|
27
|
+
], value: '16.0184897305 kg_m3'
|
28
|
+
end
|
data/lib/physical.rb
CHANGED
data/lib/physical/cuboid.rb
CHANGED
@@ -19,6 +19,12 @@ module Physical
|
|
19
19
|
Measured::Volume(dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*), :ml)
|
20
20
|
end
|
21
21
|
|
22
|
+
def density
|
23
|
+
return Measured::Density(Float::INFINITY, :g_ml) if volume.value.zero?
|
24
|
+
return Measured::Density(0.0, :g_ml) if volume.value.infinite?
|
25
|
+
Measured::Density(weight.convert_to(:g).value / volume.convert_to(:ml).value, :g_ml)
|
26
|
+
end
|
27
|
+
|
22
28
|
def ==(other)
|
23
29
|
id == other.id
|
24
30
|
end
|
data/lib/physical/package.rb
CHANGED
@@ -5,14 +5,14 @@ module Physical
|
|
5
5
|
extend Forwardable
|
6
6
|
attr_reader :container, :items, :void_fill_density, :id
|
7
7
|
|
8
|
-
def initialize(id: nil, container: nil, items: [], void_fill_density: Measured::
|
8
|
+
def initialize(id: nil, container: nil, items: [], void_fill_density: Measured::Density(0, :g_ml), dimensions: nil, weight: nil, properties: {})
|
9
9
|
@id = id || SecureRandom.uuid
|
10
|
-
@void_fill_density = Types::
|
10
|
+
@void_fill_density = Types::Density[void_fill_density]
|
11
11
|
@container = container || Physical::Box.new(dimensions: dimensions || [], weight: weight || Measured::Weight(0, :g), properties: properties)
|
12
12
|
@items = Set[*items]
|
13
13
|
end
|
14
14
|
|
15
|
-
delegate [:dimensions, :width, :length, :height, :properties] => :container
|
15
|
+
delegate [:dimensions, :width, :length, :height, :properties, :volume] => :container
|
16
16
|
|
17
17
|
def <<(item)
|
18
18
|
@items.add(item)
|
@@ -35,7 +35,13 @@ module Physical
|
|
35
35
|
def void_fill_weight
|
36
36
|
return Measured::Weight(0, :g) if container.volume.value.infinite?
|
37
37
|
|
38
|
-
Measured::Weight(void_fill_density.value * remaining_volume.value,
|
38
|
+
Measured::Weight(void_fill_density.convert_to(:g_ml).value * remaining_volume.convert_to(:ml).value, :g)
|
39
|
+
end
|
40
|
+
|
41
|
+
def density
|
42
|
+
return Measured::Density(Float::INFINITY, :g_ml) if container.volume.value.zero?
|
43
|
+
return Measured::Density(0.0, :g_ml) if container.volume.value.infinite?
|
44
|
+
Measured::Density(weight.convert_to(:g).value / container.volume.convert_to(:ml).value, :g_ml)
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
@@ -4,7 +4,7 @@ require 'factory_bot'
|
|
4
4
|
|
5
5
|
FactoryBot.define do
|
6
6
|
factory :physical_box, class: "Physical::Box" do
|
7
|
-
dimensions { [
|
7
|
+
dimensions { [20, 15, 30].map { |d| Measured::Length(d, :cm) } }
|
8
8
|
inner_dimensions { dimensions.map { |d| d - Measured::Length(1, :cm) } }
|
9
9
|
weight { Measured::Weight(0.1, :kg) }
|
10
10
|
initialize_with { new(attributes) }
|
@@ -8,7 +8,7 @@ FactoryBot.define do
|
|
8
8
|
factory :physical_package, class: "Physical::Package" do
|
9
9
|
container { FactoryBot.build(:physical_box) }
|
10
10
|
items { build_list(:physical_item, 2) }
|
11
|
-
void_fill_density { Measured::
|
11
|
+
void_fill_density { Measured::Density(0.01, :g_ml) }
|
12
12
|
initialize_with { new(attributes) }
|
13
13
|
end
|
14
14
|
end
|
data/lib/physical/types.rb
CHANGED
data/lib/physical/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: physical
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Meyerhoff
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carmen
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- ".rubocop.yml"
|
128
128
|
- ".ruby-version"
|
129
129
|
- ".travis.yml"
|
130
|
+
- CHANGELOG.md
|
130
131
|
- CODE_OF_CONDUCT.md
|
131
132
|
- Gemfile
|
132
133
|
- LICENSE.txt
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- Rakefile
|
135
136
|
- bin/console
|
136
137
|
- bin/setup
|
138
|
+
- lib/measured/density.rb
|
137
139
|
- lib/physical.rb
|
138
140
|
- lib/physical/box.rb
|
139
141
|
- lib/physical/cuboid.rb
|