physical 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e4ba860fa3455e767610003a3f3289a8258475d
4
- data.tar.gz: 64ca6a082897e15e864f008a5f62e905f3b729f3
3
+ metadata.gz: 76beac13fca836278bba298bbb217f4dd9cb4b40
4
+ data.tar.gz: 0351e63dfa2b4af7200662e2f8b8ece442e95fa9
5
5
  SHA512:
6
- metadata.gz: 949da5a40f8a79108471090cfdb7ccc20cdb726ad49b9a434332c818f7fdf1d9c6dec400ce6c114dbfe17e1ec0c98c1761ea21884a5ee39fa1f14c99bd3fd202
7
- data.tar.gz: 79d2c5fbbb2ae1551e012dbc226dfcf051368ea07008da56db96ad2f80875234fcf94d3f333115d5875545be3d27fd0525c5a94435b74f8abc85d04182356e27
6
+ metadata.gz: 6dc47ed1063302a50ecf4c65898163e94752a5ee776be58ff37663a64dcbfac51c1a7d9296d9a9fe37774c8a6f20c828faf6a6bfad6511ae58470e81c973325e
7
+ data.tar.gz: e5caf73ede430f01767575bf25b4f0a56101f0ece9d273aacdbad1ecfe70ca0dac4a24e17ddc65df9b425410e0a919d927dc32bbabcbd3a2d8259b1de19758c6
data/.circleci/config.yml CHANGED
@@ -7,7 +7,7 @@ jobs:
7
7
  build:
8
8
  docker:
9
9
  # specify the version you desire here
10
- - image: circleci/ruby:2.4.1-node-browsers
10
+ - image: circleci/ruby:2.4.5
11
11
 
12
12
  # Specify service dependencies here if necessary
13
13
  # CircleCI maintains a library of pre-built images
data/Rakefile CHANGED
@@ -1,5 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "bundler/gem_helper"
4
+ Bundler::GemHelper.install_tasks
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
@@ -4,17 +4,19 @@ require 'measured'
4
4
 
5
5
  module Physical
6
6
  class Cuboid
7
- attr_reader :dimensions, :weight, :id
7
+ attr_reader :dimensions, :width, :height, :depth, :weight, :id, :properties
8
8
 
9
- def initialize(id: nil, dimensions: [], dimension_unit: :cm, weight: 0, weight_unit: :g)
9
+ def initialize(id: nil, dimensions: [], dimension_unit: :cm, weight: 0, weight_unit: :g, properties: {})
10
10
  @id = id || SecureRandom.uuid
11
- @weight = Measured::Weight(weight, weight_unit).convert_to(:g)
12
- @dimensions = dimensions.map { |dimension| Measured::Length.new(dimension, dimension_unit).convert_to(:cm) }
11
+ @weight = Measured::Weight(weight, weight_unit)
12
+ @dimensions = dimensions.map { |dimension| Measured::Length.new(dimension, dimension_unit) }
13
13
  @dimensions.fill(Measured::Length(self.class::DEFAULT_LENGTH, dimension_unit), @dimensions.length..2)
14
+ @width, @height, @depth = *@dimensions
15
+ @properties = properties
14
16
  end
15
17
 
16
18
  def volume
17
- Measured::Volume(dimensions.map(&:value).reduce(&:*), :ml)
19
+ Measured::Volume(dimensions.map { |d| d.convert_to(:cm).value }.reduce(1, &:*), :ml)
18
20
  end
19
21
 
20
22
  def ==(other)
data/lib/physical/item.rb CHANGED
@@ -3,12 +3,5 @@
3
3
  module Physical
4
4
  class Item < Cuboid
5
5
  DEFAULT_LENGTH = 0
6
-
7
- attr_reader :properties
8
-
9
- def initialize(properties: {}, **args)
10
- @properties = properties
11
- super(args)
12
- end
13
6
  end
14
7
  end
@@ -44,8 +44,8 @@ module Physical
44
44
 
45
45
  if region.is_a?(Carmen::Region)
46
46
  @region = region
47
- elsif country.is_a?(Carmen::Country)
48
- @region = country.subregions.coded(region.to_s.upcase)
47
+ elsif @country.is_a?(Carmen::Country)
48
+ @region = @country.subregions.coded(region.to_s.upcase)
49
49
  end
50
50
 
51
51
  @name = name
@@ -2,15 +2,18 @@
2
2
 
3
3
  module Physical
4
4
  class Package
5
+ extend Forwardable
5
6
  attr_reader :container, :items, :void_fill_density, :id
6
7
 
7
8
  def initialize(id: nil, container: Physical::Box.new, items: [], void_fill_density: 0, void_fill_density_unit: :g)
8
9
  @id = id || SecureRandom.uuid
9
- @void_fill_density = Measured::Weight(void_fill_density, void_fill_density_unit)
10
+ @void_fill_density = measured_void_fill_density(void_fill_density, void_fill_density_unit)
10
11
  @container = container
11
12
  @items = Set[*items]
12
13
  end
13
14
 
15
+ def_delegator :@container, :dimensions
16
+
14
17
  def <<(item)
15
18
  @items.add(item)
16
19
  end
@@ -20,11 +23,11 @@ module Physical
20
23
  end
21
24
 
22
25
  def weight
23
- container.weight + items.map(&:weight).reduce(&:+) + void_fill_weight
26
+ container.weight + items.map(&:weight).reduce(Measured::Weight(0, :g), &:+) + void_fill_weight
24
27
  end
25
28
 
26
29
  def remaining_volume
27
- container.volume - items.map(&:volume).reduce(&:+)
30
+ container.volume - items.map(&:volume).reduce(Measured::Volume(0, :ml), &:+)
28
31
  end
29
32
 
30
33
  def void_fill_weight
@@ -32,5 +35,14 @@ module Physical
32
35
 
33
36
  Measured::Weight(void_fill_density.value * remaining_volume.value, void_fill_density.unit)
34
37
  end
38
+
39
+ def measured_void_fill_density(void_fill_density, void_fill_density_unit)
40
+ case void_fill_density
41
+ when Measured::Weight
42
+ void_fill_density
43
+ else
44
+ Measured::Weight(void_fill_density, void_fill_density_unit)
45
+ end
46
+ end
35
47
  end
36
48
  end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples 'a cuboid' do
4
+ let(:args) { {dimensions: [1.1, 2.2, 3.3], dimension_unit: :cm} }
5
+
6
+ it { is_expected.to be_a(Physical::Cuboid) }
7
+
8
+ it "has dimensions as Measured::Length objects with rational values" do
9
+ expect(subject.dimensions).to eq(
10
+ [
11
+ Measured::Length.new(1.1, :cm),
12
+ Measured::Length.new(2.2, :cm),
13
+ Measured::Length.new(3.3, :cm)
14
+ ]
15
+ )
16
+ end
17
+
18
+ it "has getter methods for each dimension as Measured::Length object" do
19
+ expect(subject.width).to eq(Measured::Length.new(1.1, :cm))
20
+ expect(subject.height).to eq(Measured::Length.new(2.2, :cm))
21
+ expect(subject.depth).to eq(Measured::Length.new(3.3, :cm))
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Physical
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
data/physical.gemspec CHANGED
@@ -21,10 +21,10 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ["lib"]
22
22
  spec.required_ruby_version = '>= 2.4'
23
23
  spec.add_runtime_dependency "carmen", "~> 1.0"
24
- spec.add_runtime_dependency "factory_bot", "~> 4.8 "
25
24
  spec.add_runtime_dependency "measured", "~> 2.4.0"
26
25
 
27
- spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "bundler", [">= 1.16", "< 3"]
27
+ spec.add_development_dependency "factory_bot", "~> 4.8"
28
28
  spec.add_development_dependency "rake", "~> 10.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-19 00:00:00.000000000 Z
11
+ date: 2019-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carmen
@@ -25,47 +25,53 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: factory_bot
28
+ name: measured
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '4.8'
33
+ version: 2.4.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.8'
40
+ version: 2.4.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: measured
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.4.0
48
- type: :runtime
47
+ version: '1.16'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '3'
51
+ type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
- version: 2.4.0
57
+ version: '1.16'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '3'
55
61
  - !ruby/object:Gem::Dependency
56
- name: bundler
62
+ name: factory_bot
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '1.16'
67
+ version: '4.8'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '1.16'
74
+ version: '4.8'
69
75
  - !ruby/object:Gem::Dependency
70
76
  name: rake
71
77
  requirement: !ruby/object:Gem::Requirement
@@ -127,6 +133,7 @@ files:
127
133
  - lib/physical/spec_support/factories/location_factory.rb
128
134
  - lib/physical/spec_support/factories/package_factory.rb
129
135
  - lib/physical/spec_support/factories/shipment_factory.rb
136
+ - lib/physical/spec_support/shared_examples.rb
130
137
  - lib/physical/version.rb
131
138
  - physical.gemspec
132
139
  homepage: https://github.com/mamhoff/physical