stockman-logic 0.1.0 → 0.1.1

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: b1950d32a54e76c7af280dfd15010366d292148d
4
- data.tar.gz: a7f9dbf94a3fe7b3ca79f75381dd305c4293aaf7
3
+ metadata.gz: cb61357fe8c09cc9baf50f841e2560c710aed169
4
+ data.tar.gz: bc8ef87c52ca47b3bf43ae1d24d8c592c753a714
5
5
  SHA512:
6
- metadata.gz: 1990b8970e576a275d849424a3a2c30e9f1bec55d031fe5d34373f02136313d2aed82d133a13dc70377bf7dca70a967076684214105e8d6d0596e4558a10216d
7
- data.tar.gz: a04285334262c0aea9b369a523b1aed976dfcf52fce0fc73d3b033d037123ed2d58d60441089ac8fdd8b094160f2e04fdfecdc08b4295c338f5f4927cf121530
6
+ metadata.gz: 19544dd10be07304ecec419fa02af609cffffcedc9be6f56860bba600766ddd5ff0b53d155524f5728e7ea3d533faee08561c64b8d0f286145de5c195d94ed74
7
+ data.tar.gz: 5e9a4d1a2a5933405ce5aa2c06cc067a5fb6e633439faf159c8b1d01d3e53bd0cadde582c1180b14e496572049bacab5e43a05387be7cb6cd6b63f7ce28ecb56
@@ -1,5 +1,5 @@
1
1
  module Stockman
2
2
  module Logic
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "redis", "~> 3.3.3"
25
25
  spec.add_development_dependency "byebug", "~> 9.1.0"
26
26
 
27
- spec.add_dependency "activesupport", '>= 3.2', '< 5.0'
27
+ spec.add_dependency "activesupport", '>= 3.2', '< 6'
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stockman-logic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliy Reys
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2017-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: '3.2'
90
90
  - - "<"
91
91
  - !ruby/object:Gem::Version
92
- version: '5.0'
92
+ version: '6'
93
93
  type: :runtime
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '3.2'
100
100
  - - "<"
101
101
  - !ruby/object:Gem::Version
102
- version: '5.0'
102
+ version: '6'
103
103
  description:
104
104
  email:
105
105
  - vasiliy.reys@gmail.com
@@ -135,7 +135,6 @@ files:
135
135
  - lib/stockman/logic/variant/stock_levels_collection.rb
136
136
  - lib/stockman/logic/version.rb
137
137
  - stockman-storage_api.gemspec
138
- - test.rb
139
138
  homepage: http://veeqo.com
140
139
  licenses:
141
140
  - MIT
@@ -161,3 +160,4 @@ signing_key:
161
160
  specification_version: 4
162
161
  summary: Stockman stock levels calculation logic
163
162
  test_files: []
163
+ has_rdoc:
data/test.rb DELETED
@@ -1,148 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'active_support/core_ext/hash'
3
- # require 'active_support/hash_with_indifferent_access'
4
- require 'pp'
5
- require 'json'
6
- require 'ostruct'
7
-
8
- module Stockman
9
- module Logic
10
- class Utils
11
- def self.deserialize_amount(value)
12
- if value == 'inf'
13
- Float::INFINITY
14
- else
15
- value.to_i
16
- end
17
- end
18
-
19
- def self.serialize_amount(value)
20
- if value == Float::INFINITY
21
- 'inf'
22
- else
23
- value.to_i
24
- end
25
- end
26
- end
27
-
28
- class Summary
29
- attr_reader :data
30
-
31
- def self.from_hash(hash)
32
- data = transform_values(hash, &Utils.method(:deserialize_amount))
33
-
34
- new(data)
35
- end
36
-
37
- def self.from_object(object)
38
- data = {
39
- physical_amount: object.total_physical_amount,
40
- allocated_amount: object.total_allocated_amount,
41
- available_amount: object.total_available_amount,
42
-
43
- warehouses: object.stock_levels.inject({}) do |memo, stock_level|
44
- memo.merge(
45
- stock_level.warehouse_id => {
46
- physical_amount: stock_level.physical_amount,
47
- allocated_amount: stock_level.allocated_amount,
48
- available_amount: stock_level.available_amount
49
- }
50
- )
51
- end
52
- }
53
-
54
- new(data)
55
- end
56
-
57
- def initialize(data)
58
- @data = data
59
- end
60
-
61
- def total_physical_amount
62
- data[:physical_amount]
63
- end
64
-
65
- def total_allocated_amount
66
- data[:allocated_amount]
67
- end
68
-
69
- def total_available_amount
70
- data[:available_amount]
71
- end
72
-
73
- def warehouses
74
- data[:warehouses]
75
- end
76
-
77
- def to_hash
78
- self.class.transform_values(data, &Utils.method(:serialize_amount))
79
- end
80
-
81
- def to_json
82
- JSON.generate(to_hash)
83
- end
84
-
85
- private
86
-
87
- def self.transform_values(hash, &block)
88
- method = lambda do |memo, data|
89
- memo.merge data[0] => yield(data[1])
90
- end
91
-
92
- totals = hash.symbolize_keys.slice(:physical_amount, :allocated_amount, :available_amount)
93
- .inject({}, &method)
94
-
95
- warehouses = hash.symbolize_keys[:warehouses].inject({}) do |memo, data|
96
- memo.merge data[0].to_i => data[1].inject({}, &method).symbolize_keys
97
- end
98
-
99
- totals.merge(warehouses: warehouses)
100
- end
101
- end
102
- end
103
- end
104
-
105
- data = {
106
- physical_amount: Float::INFINITY,
107
- allocated_amount: 40,
108
- available_amount: Float::INFINITY,
109
-
110
- warehouses: {
111
- 17 => {
112
- physical_amount: Float::INFINITY,
113
- allocated_amount: 10,
114
- available_amount: Float::INFINITY
115
- },
116
- 18 => {
117
- physical_amount: 500,
118
- allocated_amount: 30,
119
- available_amount: 470
120
- }
121
- }
122
- }
123
-
124
- object = OpenStruct.new(
125
- total_physical_amount: Float::INFINITY,
126
- total_allocated_amount: 40,
127
- total_available_amount: Float::INFINITY,
128
- stock_levels: [
129
- OpenStruct.new(
130
- warehouse_id: 17,
131
- physical_amount: Float::INFINITY,
132
- allocated_amount: 10,
133
- available_amount: Float::INFINITY
134
- ),
135
- OpenStruct.new(
136
- warehouse_id: 18,
137
- physical_amount: 500,
138
- allocated_amount: 30,
139
- available_amount: 470
140
- )
141
- ]
142
- )
143
-
144
- json = %Q{{"physical_amount":"inf","allocated_amount":40,"available_amount":"inf","warehouses":{"17":{"physical_amount":"inf","allocated_amount":10,"available_amount":"inf"},"18":{"physical_amount":500,"allocated_amount":30,"available_amount":470}}}}
145
-
146
- puts Stockman::Logic::Summary.new(data).to_hash
147
- puts Stockman::Logic::Summary.from_hash(JSON.parse(json)).to_hash
148
- puts Stockman::Logic::Summary.from_object(object).to_hash