hash_math 1.2.0.pre.alpha → 1.2.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 +1 -1
- data/lib/hash_math/mapper.rb +6 -0
- data/lib/hash_math/mapper/mapping.rb +1 -1
- data/lib/hash_math/version.rb +1 -1
- data/spec/hash_math/mapper_spec.rb +56 -34
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a13830be433114e0438c34e2e15e136a01ab61c93b57c14e9be2b39a4dc9a7bf
|
4
|
+
data.tar.gz: 14a4d2765184d10f6149dd446be54f1cea68c505e308fbf884a982cecc0ad161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5294dee4cb58c9d28cc829b2d18a51edb6036bf110c2ad94bc827e52d80e6b7417cf96e5b699af812b91d6b9ee9be75e2ba2f796a65234e333f68f3fb587033
|
7
|
+
data.tar.gz: '0706231920aa50e791e43820e9544a399d132ff9f5a1ee29cd0fc2c70414ecb181d28350a4aa3f1b5df67bdf904dc93b876246cfdb4e53507e33358e1100de71'
|
data/CHANGELOG.md
CHANGED
data/lib/hash_math/mapper.rb
CHANGED
@@ -26,12 +26,18 @@ module HashMath
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Add an enumerable list of lookup records to this instance's lookup dataset.
|
29
|
+
# Raises ArgumentError if name is blank.
|
29
30
|
def add_each(name, objects)
|
31
|
+
raise ArgumentError, 'name is required' if name.to_s.empty?
|
32
|
+
|
30
33
|
tap { objects.each { |o| add(name, o) } }
|
31
34
|
end
|
32
35
|
|
33
36
|
# Add a lookup record to this instance's lookup dataset.
|
37
|
+
# Raises ArgumentError if name is blank.
|
34
38
|
def add(name, object)
|
39
|
+
raise ArgumentError, 'name is required' if name.to_s.empty?
|
40
|
+
|
35
41
|
tap { mappings_by_name.fetch(name.to_s).add(object) }
|
36
42
|
end
|
37
43
|
|
@@ -33,7 +33,7 @@ module HashMath
|
|
33
33
|
|
34
34
|
attr_reader :value, :set, :with, :lookup
|
35
35
|
|
36
|
-
def_delegators :lookup, :name, :by
|
36
|
+
def_delegators :lookup, :name, :by
|
37
37
|
|
38
38
|
# lookup: can either be a Mapper#Lookup instance or a hash with the attributes to initialize
|
39
39
|
# for a Mapper#Lookup instance.
|
data/lib/hash_math/version.rb
CHANGED
@@ -63,55 +63,77 @@ describe HashMath::Mapper do
|
|
63
63
|
{ patient_id: 2, patient_status: 'doesnt_exist', marital_status: 'no_exist' }
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
|
-
it '
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
66
|
+
describe '#add' do
|
67
|
+
it 'raises ArgumentError when name is nil' do
|
68
|
+
expect { subject.add(nil, {}) }.to raise_error(ArgumentError)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'raises ArgumentError when name is empty string' do
|
72
|
+
expect { subject.add('', {}) }.to raise_error(ArgumentError)
|
73
|
+
end
|
74
|
+
end
|
72
75
|
|
73
|
-
|
76
|
+
describe '#add_each' do
|
77
|
+
it 'raises ArgumentError when name is nil' do
|
78
|
+
expect { subject.add_each(nil, []) }.to raise_error(ArgumentError)
|
79
|
+
end
|
74
80
|
|
75
|
-
|
81
|
+
it 'raises ArgumentError when name is empty string' do
|
82
|
+
expect { subject.add_each('', []) }.to raise_error(ArgumentError)
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
86
|
+
describe '#map' do
|
87
|
+
context 'with nil input' do
|
88
|
+
it 'returns base mapped hash' do
|
89
|
+
expected = {
|
90
|
+
patient_status_id: nil,
|
91
|
+
marital_status_id: nil
|
92
|
+
}
|
85
93
|
|
86
|
-
|
94
|
+
actual = subject.map(nil)
|
87
95
|
|
88
|
-
|
96
|
+
expect(actual).to eq(expected)
|
97
|
+
end
|
89
98
|
end
|
90
|
-
end
|
91
99
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
100
|
+
context 'with missing keys input' do
|
101
|
+
it 'returns hash with nil values' do
|
102
|
+
expected = omitted.merge(
|
103
|
+
patient_status_id: nil,
|
104
|
+
marital_status_id: nil
|
105
|
+
)
|
98
106
|
|
99
|
-
|
107
|
+
actual = subject.map(omitted)
|
100
108
|
|
101
|
-
|
109
|
+
expect(actual).to eq(expected)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with present keys input' do
|
114
|
+
it 'returns hash with values' do
|
115
|
+
expected = filled.merge(
|
116
|
+
patient_status_id: 1,
|
117
|
+
marital_status_id: 1
|
118
|
+
)
|
119
|
+
|
120
|
+
actual = subject.map(filled)
|
121
|
+
|
122
|
+
expect(actual).to eq(expected)
|
123
|
+
end
|
102
124
|
end
|
103
|
-
end
|
104
125
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
126
|
+
context 'with present keys input but no values match lookups' do
|
127
|
+
it 'returns hash with nil values' do
|
128
|
+
expected = mismatched.merge(
|
129
|
+
patient_status_id: nil,
|
130
|
+
marital_status_id: nil
|
131
|
+
)
|
111
132
|
|
112
|
-
|
133
|
+
actual = subject.map(mismatched)
|
113
134
|
|
114
|
-
|
135
|
+
expect(actual).to eq(expected)
|
136
|
+
end
|
115
137
|
end
|
116
138
|
end
|
117
139
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_math
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
@@ -194,9 +194,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '2.5'
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
|
-
- - "
|
197
|
+
- - ">="
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
199
|
+
version: '0'
|
200
200
|
requirements: []
|
201
201
|
rubygems_version: 3.0.3
|
202
202
|
signing_key:
|