ncs_mdes 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/lib/ncs_navigator/mdes/variable.rb +33 -9
- data/lib/ncs_navigator/mdes/version.rb +1 -1
- data/spec/ncs_navigator/mdes/variable_spec.rb +74 -0
- metadata +38 -7
data/CHANGELOG.md
CHANGED
@@ -31,11 +31,26 @@ module NcsNavigator::Mdes
|
|
31
31
|
attr_accessor :type
|
32
32
|
|
33
33
|
##
|
34
|
-
#
|
34
|
+
# If the variable does not have a value, should it be completely
|
35
|
+
# omitted when submitting to the VDR?
|
35
36
|
#
|
36
37
|
# @return [Boolean]
|
37
|
-
attr_accessor :
|
38
|
-
alias :
|
38
|
+
attr_accessor :omittable
|
39
|
+
alias :omittable? :omittable
|
40
|
+
|
41
|
+
##
|
42
|
+
# May the variable be submitted as a null value?
|
43
|
+
#
|
44
|
+
# @return [Boolean]
|
45
|
+
attr_accessor :nillable
|
46
|
+
alias :nillable? :nillable
|
47
|
+
|
48
|
+
##
|
49
|
+
# Allows for an override of the default logic. Mostly intended for
|
50
|
+
# testing. Set to `nil` to restore default logic.
|
51
|
+
#
|
52
|
+
# @return [Boolean,nil]
|
53
|
+
attr_writer :required
|
39
54
|
|
40
55
|
##
|
41
56
|
# If this variable is a foreign key, this is the {table
|
@@ -57,12 +72,8 @@ module NcsNavigator::Mdes
|
|
57
72
|
log = options[:log] || NcsNavigator::Mdes.default_logger
|
58
73
|
|
59
74
|
new(element['name']).tap do |var|
|
60
|
-
var.
|
61
|
-
|
62
|
-
element['minOccurs'] != '0'
|
63
|
-
else
|
64
|
-
element['nillable'] == 'false'
|
65
|
-
end
|
75
|
+
var.nillable = element['nillable'] == 'true'
|
76
|
+
var.omittable = element['minOccurs'] == '0'
|
66
77
|
var.pii =
|
67
78
|
case element['pii']
|
68
79
|
when 'Y'; true;
|
@@ -104,6 +115,19 @@ module NcsNavigator::Mdes
|
|
104
115
|
@constraints ||= []
|
105
116
|
end
|
106
117
|
|
118
|
+
##
|
119
|
+
# Is a value for the variable mandatory for a valid submission?
|
120
|
+
#
|
121
|
+
# @return [Boolean]
|
122
|
+
def required?
|
123
|
+
if @required.nil?
|
124
|
+
!(omittable? || nillable?)
|
125
|
+
else
|
126
|
+
@required
|
127
|
+
end
|
128
|
+
end
|
129
|
+
alias :required :required?
|
130
|
+
|
107
131
|
##
|
108
132
|
# If the {#type} of this instance is a reference to an NCS type,
|
109
133
|
# attempts to replace it with the full version from the given list
|
@@ -107,6 +107,34 @@ XSD
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
|
110
|
+
describe '#omittable?' do
|
111
|
+
it 'is true when minOccurs is 0' do
|
112
|
+
variable('<xs:element minOccurs="0"/>').should be_omittable
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'is false when minOccurs is not present' do
|
116
|
+
comments.should_not be_omittable
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'is false when minOccurs is > 0' do
|
120
|
+
variable('<xs:element minOccurs="1"/>').should_not be_omittable
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#nillable?' do
|
125
|
+
it 'is true when nillable is true' do
|
126
|
+
variable('<xs:element nillable="true"/>').should be_nillable
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'is false when nillable is not present' do
|
130
|
+
variable('<xs:element/>').should_not be_nillable
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'is false when nillable is false' do
|
134
|
+
variable('<xs:element nillable="false"/>').should_not be_nillable
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
110
138
|
describe '#pii' do
|
111
139
|
it 'is false when blank' do
|
112
140
|
variable('<xs:element ncsdoc:pii=""/>').pii.should == false
|
@@ -156,6 +184,52 @@ XSD
|
|
156
184
|
end
|
157
185
|
end
|
158
186
|
|
187
|
+
describe '#required?' do
|
188
|
+
subject { Variable.new('foo') }
|
189
|
+
|
190
|
+
it 'is true when not omittable or nillable' do
|
191
|
+
subject.should be_required
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'is false when omittable only' do
|
195
|
+
subject.omittable = true
|
196
|
+
subject.should_not be_required
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'is false when nillable only' do
|
200
|
+
subject.nillable = true
|
201
|
+
subject.should_not be_required
|
202
|
+
end
|
203
|
+
|
204
|
+
it 'is false both nillable and omittable' do
|
205
|
+
subject.nillable = true
|
206
|
+
subject.omittable = true
|
207
|
+
subject.should_not be_required
|
208
|
+
end
|
209
|
+
|
210
|
+
describe 'when explicitly set' do
|
211
|
+
it 'preserves trueness even when would be false' do
|
212
|
+
subject.nillable = true
|
213
|
+
subject.required = true
|
214
|
+
subject.should be_required
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'preserves falseness even when should be true' do
|
218
|
+
subject.required = false
|
219
|
+
subject.should_not be_required
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'can be cleared by setting to nil' do
|
223
|
+
subject.nillable = true
|
224
|
+
subject.required = true
|
225
|
+
subject.should be_required
|
226
|
+
|
227
|
+
subject.required = nil
|
228
|
+
subject.should_not be_required
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
159
233
|
describe '#resolve_type!' do
|
160
234
|
let(:reference_type) { VariableType.reference('ncs:color_cl3') }
|
161
235
|
let(:actual_type) { VariableType.new('color_cl3') }
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncs_mdes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 13
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 1
|
10
|
+
version: 0.4.1
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Rhett Sutphin
|
@@ -10,7 +15,7 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-31 00:00:00 -05:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
@@ -21,6 +26,10 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ~>
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 4
|
24
33
|
version: "1.4"
|
25
34
|
type: :runtime
|
26
35
|
version_requirements: *id001
|
@@ -32,6 +41,10 @@ dependencies:
|
|
32
41
|
requirements:
|
33
42
|
- - ~>
|
34
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 15
|
45
|
+
segments:
|
46
|
+
- 2
|
47
|
+
- 6
|
35
48
|
version: "2.6"
|
36
49
|
type: :development
|
37
50
|
version_requirements: *id002
|
@@ -43,6 +56,11 @@ dependencies:
|
|
43
56
|
requirements:
|
44
57
|
- - ~>
|
45
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 63
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 9
|
63
|
+
- 2
|
46
64
|
version: 0.9.2
|
47
65
|
type: :development
|
48
66
|
version_requirements: *id003
|
@@ -54,12 +72,19 @@ dependencies:
|
|
54
72
|
requirements:
|
55
73
|
- - ~>
|
56
74
|
- !ruby/object:Gem::Version
|
75
|
+
hash: 7
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
- 7
|
79
|
+
- 2
|
57
80
|
version: 0.7.2
|
58
81
|
type: :development
|
59
82
|
version_requirements: *id004
|
60
|
-
description:
|
61
|
-
|
62
|
-
|
83
|
+
description: |
|
84
|
+
|
85
|
+
Provides a consistent ruby interface to the project metainformation in the
|
86
|
+
National Children's Study's Master Data Element Specification.
|
87
|
+
|
63
88
|
email:
|
64
89
|
- r-sutphin@northwestern.edu
|
65
90
|
executables:
|
@@ -113,17 +138,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
138
|
requirements:
|
114
139
|
- - ">="
|
115
140
|
- !ruby/object:Gem::Version
|
141
|
+
hash: 3
|
142
|
+
segments:
|
143
|
+
- 0
|
116
144
|
version: "0"
|
117
145
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
146
|
none: false
|
119
147
|
requirements:
|
120
148
|
- - ">="
|
121
149
|
- !ruby/object:Gem::Version
|
150
|
+
hash: 3
|
151
|
+
segments:
|
152
|
+
- 0
|
122
153
|
version: "0"
|
123
154
|
requirements: []
|
124
155
|
|
125
156
|
rubyforge_project:
|
126
|
-
rubygems_version: 1.
|
157
|
+
rubygems_version: 1.3.7
|
127
158
|
signing_key:
|
128
159
|
specification_version: 3
|
129
160
|
summary: A ruby API for various versions of the NCS MDES.
|