physical 0.3.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 436cc77723f0d4fd9fed0af142621244e8503eb2
4
- data.tar.gz: ac7630ca5e91fb68d494659180994853445e5f76
3
+ metadata.gz: 69552008d60146d8d2aff0d47ae732a1baf06d3f
4
+ data.tar.gz: 4bdd77b725a51cf6aa989ddf34ca4b08fc92e5f6
5
5
  SHA512:
6
- metadata.gz: 187cacca3d21bf5d18d65b5937ca3d29938947dec49580ef76fe3efe3cb4c2fd2e8844caf9ce0272526c9ae58eb5919b88755233b07096104b8dfda75688490a
7
- data.tar.gz: a8a717b05c47c40eb866750f8852e22d5ce3bbd4389ace0f72190faa759119fa3fe80752d3a2c754acf95627de777b45903b20244ef6a03b192f16df5b2ebe7a
6
+ metadata.gz: 02e59b75eab848337c424e2c941a752d3328235987f65e031330de022cd50e04b41db8f5488c31bc614a0374e10627478b87a93db2e697f6b8319e633f25372c
7
+ data.tar.gz: eb257f74a3353fed64edf7579043e8dcf76a2d52b35653201841d05d091f528cbd66abd1faf4d2c5207557eb66c8e193c513aa6dbdaf47cabf30eec43b252849
@@ -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
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "measured/density"
3
4
  require "physical/types"
4
5
  require "physical/version"
5
6
  require "physical/cuboid"
@@ -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
@@ -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::Weight(0, :g), dimensions: nil, weight: nil, properties: {})
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::Weight[void_fill_density]
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, void_fill_density.unit)
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 { [4, 5, 6].map { |d| Measured::Length(d, :dm) } }
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::Weight(0.01, :g) }
11
+ void_fill_density { Measured::Density(0.01, :g_ml) }
12
12
  initialize_with { new(attributes) }
13
13
  end
14
14
  end
@@ -8,6 +8,7 @@ module Physical
8
8
  Weight = Types.Instance(::Measured::Weight)
9
9
  Length = Types.Instance(::Measured::Length)
10
10
  Volume = Types.Instance(::Measured::Volume)
11
+ Density = Types.Instance(::Measured::Density)
11
12
 
12
13
  Dimensions = Types::Strict::Array.of(Length)
13
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Physical
4
- VERSION = "0.3.3"
4
+ VERSION = "0.4.0"
5
5
  end
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.3.3
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-01 00:00:00.000000000 Z
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