hash_math 0.0.1 → 1.2.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.
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe HashMath::Unpivot::Pivot do
13
+ let(:config) do
14
+ {
15
+ keys: %i[first_exam_date last_exam_date consent_date],
16
+ coalesce_key: :field,
17
+ coalesce_key_value: :value
18
+ }
19
+ end
20
+
21
+ let(:patient) do
22
+ {
23
+ patient_id: 2,
24
+ first_exam_date: '2020-01-03',
25
+ last_exam_date: '2020-04-05',
26
+ consent_date: '2020-01-02'
27
+ }
28
+ end
29
+
30
+ subject { described_class.make(config) }
31
+
32
+ describe '#expand' do
33
+ it 'performs a single un-pivoting' do
34
+ actual = subject.expand({}, patient)
35
+
36
+ expected = [
37
+ {
38
+ field: :first_exam_date,
39
+ value: '2020-01-03'
40
+ },
41
+ {
42
+ field: :last_exam_date,
43
+ value: '2020-04-05'
44
+ },
45
+ {
46
+ field: :consent_date, value: '2020-01-02'
47
+ }
48
+ ]
49
+
50
+ expect(actual).to match_array(expected)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,121 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2019-present, Blue Marble Payroll, LLC
5
+ #
6
+ # This source code is licensed under the MIT license found in the
7
+ # LICENSE file in the root directory of this source tree.
8
+ #
9
+
10
+ require 'spec_helper'
11
+
12
+ describe HashMath::Unpivot do
13
+ let(:a_and_b_pivot) do
14
+ {
15
+ keys: %i[a b],
16
+ coalesce_key: :ab_key,
17
+ coalesce_key_value: :ab_value
18
+ }
19
+ end
20
+
21
+ let(:cd_and_e_pivot) do
22
+ {
23
+ keys: %i[c d e],
24
+ coalesce_key: :cde_key,
25
+ coalesce_key_value: :cde_value
26
+ }
27
+ end
28
+
29
+ let(:hash) do
30
+ { a: 1, b: 2, c: 3, d: 4, e: 5 }
31
+ end
32
+
33
+ context 'with no pivots' do
34
+ it 'returns the inputted hash only' do
35
+ actual = subject.expand(hash)
36
+
37
+ expect(actual).to match_array([hash])
38
+ end
39
+ end
40
+
41
+ context 'with nil inputted' do
42
+ it 'returns array with nil' do
43
+ actual = subject.expand(nil)
44
+
45
+ expect(actual).to match_array([nil])
46
+ end
47
+ end
48
+
49
+ context 'with one pivot' do
50
+ it 'coalesces two columns into two rows' do
51
+ subject.add(**a_and_b_pivot)
52
+
53
+ expected = [
54
+ { ab_key: :a, ab_value: 1, c: 3, d: 4, e: 5 },
55
+ { ab_key: :b, ab_value: 2, c: 3, d: 4, e: 5 }
56
+ ]
57
+
58
+ actual = subject.expand(hash)
59
+
60
+ expect(actual).to eq(expected)
61
+ end
62
+ end
63
+
64
+ context 'with two pivots' do
65
+ it 'coalesces five columns into six rows' do
66
+ subject.add(**a_and_b_pivot).add(**cd_and_e_pivot)
67
+
68
+ expected = [
69
+ { ab_key: :a, ab_value: 1, cde_key: :c, cde_value: 3 },
70
+ { ab_key: :b, ab_value: 2, cde_key: :c, cde_value: 3 },
71
+ { ab_key: :a, ab_value: 1, cde_key: :d, cde_value: 4 },
72
+ { ab_key: :b, ab_value: 2, cde_key: :d, cde_value: 4 },
73
+ { ab_key: :a, ab_value: 1, cde_key: :e, cde_value: 5 },
74
+ { ab_key: :b, ab_value: 2, cde_key: :e, cde_value: 5 }
75
+ ]
76
+
77
+ actual = subject.expand(hash)
78
+
79
+ expect(actual).to match_array expected
80
+ end
81
+ end
82
+
83
+ describe 'README examples' do
84
+ context 'single patient row and one pivot example' do
85
+ let(:patient) do
86
+ {
87
+ patient_id: 2,
88
+ first_exam_date: '2020-01-03',
89
+ last_exam_date: '2020-04-05',
90
+ consent_date: '2020-01-02'
91
+ }
92
+ end
93
+
94
+ let(:pivot_set) do
95
+ {
96
+ pivots: [
97
+ {
98
+ keys: %i[first_exam_date last_exam_date consent_date],
99
+ coalesce_key: :field,
100
+ coalesce_key_value: :value
101
+ }
102
+ ]
103
+ }
104
+ end
105
+
106
+ subject { HashMath::Unpivot.new(pivot_set) }
107
+
108
+ it 'extrapolates one row into N rows (one per column key)' do
109
+ expected = [
110
+ { patient_id: 2, field: :first_exam_date, value: '2020-01-03' },
111
+ { patient_id: 2, field: :last_exam_date, value: '2020-04-05' },
112
+ { patient_id: 2, field: :consent_date, value: '2020-01-02' }
113
+ ]
114
+
115
+ actual = subject.expand(patient)
116
+
117
+ expect(actual).to match_array(expected)
118
+ end
119
+ end
120
+ end
121
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_math
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-16 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: acts_as_hashable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: guard-rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,20 +52,34 @@ dependencies:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: '12'
75
+ version: '13.0'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: '12'
82
+ version: '13.0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -72,42 +100,42 @@ dependencies:
72
100
  requirements:
73
101
  - - "~>"
74
102
  - !ruby/object:Gem::Version
75
- version: 0.74.0
103
+ version: 0.88.0
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
108
  - - "~>"
81
109
  - !ruby/object:Gem::Version
82
- version: 0.74.0
110
+ version: 0.88.0
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: simplecov
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - "~>"
88
116
  - !ruby/object:Gem::Version
89
- version: 0.17.0
117
+ version: 0.18.5
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
122
  - - "~>"
95
123
  - !ruby/object:Gem::Version
96
- version: 0.17.0
124
+ version: 0.18.5
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: simplecov-console
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - "~>"
102
130
  - !ruby/object:Gem::Version
103
- version: 0.5.0
131
+ version: 0.7.0
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
- version: 0.5.0
138
+ version: 0.7.0
111
139
  description: " This library offers general purpose higher-level data structures
112
140
  that focus on Hash manipulation.\n"
113
141
  email:
@@ -132,7 +160,24 @@ files:
132
160
  - bin/console
133
161
  - hash_math.gemspec
134
162
  - lib/hash_math.rb
163
+ - lib/hash_math/mapper.rb
164
+ - lib/hash_math/mapper/lookup.rb
165
+ - lib/hash_math/mapper/mapping.rb
166
+ - lib/hash_math/matrix.rb
167
+ - lib/hash_math/matrix/key_value_pair.rb
168
+ - lib/hash_math/record.rb
169
+ - lib/hash_math/table.rb
170
+ - lib/hash_math/unpivot.rb
171
+ - lib/hash_math/unpivot/pivot.rb
172
+ - lib/hash_math/unpivot/pivot_set.rb
135
173
  - lib/hash_math/version.rb
174
+ - spec/hash_math/mapper/mapping_spec.rb
175
+ - spec/hash_math/mapper_spec.rb
176
+ - spec/hash_math/matrix_spec.rb
177
+ - spec/hash_math/record_spec.rb
178
+ - spec/hash_math/table_spec.rb
179
+ - spec/hash_math/unpivot/pivot_spec.rb
180
+ - spec/hash_math/unpivot_spec.rb
136
181
  - spec/spec_helper.rb
137
182
  homepage: https://github.com/bluemarblepayroll/hash_math
138
183
  licenses:
@@ -146,7 +191,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
191
  requirements:
147
192
  - - ">="
148
193
  - !ruby/object:Gem::Version
149
- version: 2.3.8
194
+ version: '2.5'
150
195
  required_rubygems_version: !ruby/object:Gem::Requirement
151
196
  requirements:
152
197
  - - ">="
@@ -158,4 +203,11 @@ signing_key:
158
203
  specification_version: 4
159
204
  summary: Hash-based data structures and algorithms
160
205
  test_files:
206
+ - spec/hash_math/mapper/mapping_spec.rb
207
+ - spec/hash_math/mapper_spec.rb
208
+ - spec/hash_math/matrix_spec.rb
209
+ - spec/hash_math/record_spec.rb
210
+ - spec/hash_math/table_spec.rb
211
+ - spec/hash_math/unpivot/pivot_spec.rb
212
+ - spec/hash_math/unpivot_spec.rb
161
213
  - spec/spec_helper.rb