@@ -89,28 +89,32 @@ def simple_code_list_to_json(model, doc)
89
89
90
90
def lookup ( path )
91
91
parts = path . split ( ">" )
92
- conditions = parts [ 0 ] . split ( "," ) . map { |c | c . split ( ":" ) } . to_h
92
+ conditions = parts [ 0 ] . split ( "," ) . to_h { |c | c . split ( ":" ) }
93
93
target_column = parts [ 1 ]
94
94
95
95
result = simple_code_list . row . find do |row |
96
96
conditions . all? do |col , value |
97
97
column = column_set . column . find { |c | c . short_name . content . downcase == col . downcase }
98
98
raise Error , "Column not found: #{ col } " unless column
99
+
99
100
row_value = row . value . find { |v | v . column_ref == column . id } &.simple_value &.content
100
101
row_value == value
101
102
end
102
103
end
103
104
104
- if result
105
- if target_column
106
- column = column_set . column . find { |c | c . short_name . content . downcase == target_column . downcase }
107
- raise Error , "Target column not found: #{ target_column } " unless column
108
- result . value . find { |v | v . column_ref == column . id } &.simple_value &.content
109
- else
110
- result . value . map { |v | [ column_set . column . find { |c | c . id == v . column_ref } . short_name . content , v . simple_value . content ] } . to_h
111
- end
105
+ raise Error , "No matching row found for path: #{ path } " unless result
106
+
107
+ if target_column
108
+ column = column_set . column . find { |c | c . short_name . content . downcase == target_column . downcase }
109
+ raise Error , "Target column not found: #{ target_column } " unless column
110
+
111
+ result . value . find { |v | v . column_ref == column . id } &.simple_value &.content
112
112
else
113
- raise Error , "No matching row found for path: #{ path } "
113
+ result . value . to_h do |v |
114
+ [ column_set . column . find do |c |
115
+ c . id == v . column_ref
116
+ end . short_name . content , v . simple_value . content , ]
117
+ end
114
118
end
115
119
end
116
120
@@ -122,10 +126,16 @@ def validate_verbose
122
126
errors = [ ]
123
127
124
128
# Rule 1: ColumnSet presence
125
- errors << { code : "MISSING_COLUMN_SET" , message : "ColumnSet is missing or empty" } if column_set . nil? || column_set . column . empty?
129
+ if column_set . nil? || column_set . column . empty?
130
+ errors << { code : "MISSING_COLUMN_SET" ,
131
+ message : "ColumnSet is missing or empty" , }
132
+ end
126
133
127
134
# Rule 2: SimpleCodeList presence
128
- errors << { code : "MISSING_SIMPLE_CODE_LIST" , message : "SimpleCodeList is missing or empty" } if simple_code_list . nil? || simple_code_list . row . empty?
135
+ if simple_code_list . nil? || simple_code_list . row . empty?
136
+ errors << { code : "MISSING_SIMPLE_CODE_LIST" ,
137
+ message : "SimpleCodeList is missing or empty" , }
138
+ end
129
139
130
140
# Rule 3: Unique column IDs
131
141
column_ids = column_set &.column &.map ( &:id ) || [ ]
@@ -137,7 +147,8 @@ def validate_verbose
137
147
simple_code_list &.row &.each_with_index do |row , index |
138
148
row . value . each do |value |
139
149
unless column_ids . include? ( value . column_ref )
140
- errors << { code : "INVALID_COLUMN_REF" , message : "Invalid ColumnRef '#{ value . column_ref } ' in row #{ index + 1 } " }
150
+ errors << { code : "INVALID_COLUMN_REF" ,
151
+ message : "Invalid ColumnRef '#{ value . column_ref } ' in row #{ index + 1 } " , }
141
152
end
142
153
end
143
154
end
@@ -158,7 +169,8 @@ def validate_verbose
158
169
simple_code_list &.row &.each_with_index do |row , index |
159
170
required_columns . each do |col |
160
171
unless row . value . any? { |v | v . column_ref == col . id && v . simple_value &.content }
161
- errors << { code : "MISSING_REQUIRED_VALUE" , message : "Missing value for required column '#{ col . short_name &.content } ' in row #{ index + 1 } " }
172
+ errors << { code : "MISSING_REQUIRED_VALUE" ,
173
+ message : "Missing value for required column '#{ col . short_name &.content } ' in row #{ index + 1 } " , }
162
174
end
163
175
end
164
176
end
@@ -169,7 +181,8 @@ def validate_verbose
169
181
simple_code_list &.row &.each_with_index do |row , index |
170
182
value = row . value . find { |v | v . column_ref == col . id } &.simple_value &.content
171
183
unless value_matches_type? ( value , data_type )
172
- errors << { code : "INVALID_DATA_TYPE" , message : "Invalid data type for column '#{ col . short_name &.content } ' in row #{ index + 1 } " }
184
+ errors << { code : "INVALID_DATA_TYPE" ,
185
+ message : "Invalid data type for column '#{ col . short_name &.content } ' in row #{ index + 1 } " , }
173
186
end
174
187
end
175
188
end
@@ -182,21 +195,20 @@ def validate_verbose
182
195
# Rule 19: Datatype ID validation
183
196
column_set &.column &.each do |col |
184
197
if col . data &.type && !valid_datatype_id? ( col . data . type )
185
- errors << { code : "INVALID_DATATYPE_ID" , message : "Invalid datatype ID for column '#{ col . short_name &.content } '" }
198
+ errors << { code : "INVALID_DATATYPE_ID" ,
199
+ message : "Invalid datatype ID for column '#{ col . short_name &.content } '" , }
186
200
end
187
- end
188
201
189
- # Rule 20 and 22: Complex data validation
190
- column_set &.column &.each do |col |
202
+ # Rule 20 and 22: Complex data validation
191
203
if col . data &.type == "*" && col . data &.datatype_library != "*"
192
- errors << { code : "INVALID_COMPLEX_DATA" , message : "Invalid complex data configuration for column '#{ col . short_name &.content } '" }
204
+ errors << { code : "INVALID_COMPLEX_DATA" ,
205
+ message : "Invalid complex data configuration for column '#{ col . short_name &.content } '" , }
193
206
end
194
- end
195
207
196
- # Rule 23: Language attribute validation
197
- column_set &.column &.each do |col |
208
+ # Rule 23: Language attribute validation
198
209
if col . data &.lang && col . data_restrictions &.lang
199
- errors << { code : "DUPLICATE_LANG_ATTRIBUTE" , message : "Duplicate lang attribute for column '#{ col . short_name &.content } '" }
210
+ errors << { code : "DUPLICATE_LANG_ATTRIBUTE" ,
211
+ message : "Duplicate lang attribute for column '#{ col . short_name &.content } '" , }
200
212
end
201
213
end
202
214
@@ -210,17 +222,19 @@ def validate_verbose
210
222
# Rule 39: ShortName whitespace check
211
223
column_set &.column &.each do |col |
212
224
if col . short_name &.content &.match? ( /\s / )
213
- errors << { code : "INVALID_SHORT_NAME" , message : "ShortName '#{ col . short_name &.content } ' contains whitespace" }
225
+ errors << { code : "INVALID_SHORT_NAME" ,
226
+ message : "ShortName '#{ col . short_name &.content } ' contains whitespace" , }
214
227
end
215
228
end
216
229
217
230
# Rule 42 and 43: ComplexValue validation
218
231
simple_code_list &.row &.each_with_index do |row , index |
219
232
row . value . each do |value |
220
- if value . complex_value
221
- unless valid_complex_value? ( value . complex_value , column_set &.column &.find { |c | c . id == value . column_ref } )
222
- errors << { code : "INVALID_COMPLEX_VALUE" , message : "Invalid ComplexValue in row #{ index + 1 } , column '#{ value . column_ref } '" }
223
- end
233
+ next unless value . complex_value
234
+
235
+ unless valid_complex_value? ( value . complex_value , column_set &.column &.find { |c | c . id == value . column_ref } )
236
+ errors << { code : "INVALID_COMPLEX_VALUE" ,
237
+ message : "Invalid ComplexValue in row #{ index + 1 } , column '#{ value . column_ref } '" , }
224
238
end
225
239
end
226
240
end
@@ -237,9 +251,17 @@ def value_matches_type?(value, type)
237
251
when "integer"
238
252
value . to_i . to_s == value
239
253
when "decimal"
240
- Float ( value ) rescue false
254
+ begin
255
+ Float ( value )
256
+ rescue StandardError
257
+ false
258
+ end
241
259
when "date"
242
- Date . parse ( value ) rescue false
260
+ begin
261
+ Date . parse ( value )
262
+ rescue StandardError
263
+ false
264
+ end
243
265
else
244
266
true # If type is unknown, consider it valid
245
267
end
@@ -250,7 +272,7 @@ def valid_uri?(uri)
250
272
end
251
273
252
274
def valid_datatype_id? ( id )
253
- [ " string" , " token" , " boolean" , " decimal" , " integer" , " date" ] . include? ( id )
275
+ %w[ string token boolean decimal integer date ] . include? ( id )
254
276
end
255
277
256
278
def valid_complex_value? ( complex_value , column )
0 commit comments