genericode 0.1.3 → 0.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -28
- data/.rubocop_todo.yml +36 -12
- data/Rakefile +3 -3
- data/exe/genericode +2 -2
- data/lib/genericode/agency.rb +15 -16
- data/lib/genericode/annotation.rb +9 -10
- data/lib/genericode/any_other_content.rb +2 -3
- data/lib/genericode/any_other_language_content.rb +6 -6
- data/lib/genericode/canonical_uri.rb +3 -3
- data/lib/genericode/cli/code_lister.rb +19 -14
- data/lib/genericode/cli/code_lookup.rb +1 -1
- data/lib/genericode/cli/commands.rb +21 -18
- data/lib/genericode/cli/converter.rb +10 -4
- data/lib/genericode/cli/validator.rb +12 -5
- data/lib/genericode/cli.rb +1 -1
- data/lib/genericode/code_list.rb +64 -63
- data/lib/genericode/code_list_ref.rb +12 -13
- data/lib/genericode/code_list_set.rb +20 -21
- data/lib/genericode/code_list_set_ref.rb +14 -14
- data/lib/genericode/column.rb +31 -32
- data/lib/genericode/column_ref.rb +18 -19
- data/lib/genericode/column_set.rb +22 -23
- data/lib/genericode/column_set_ref.rb +9 -10
- data/lib/genericode/data.rb +14 -15
- data/lib/genericode/data_restrictions.rb +7 -8
- data/lib/genericode/datatype_facet.rb +8 -9
- data/lib/genericode/gc_namespace.rb +12 -0
- data/lib/genericode/general_identifier.rb +9 -9
- data/lib/genericode/identification.rb +31 -32
- data/lib/genericode/json/canonical_uri_mixin.rb +1 -1
- data/lib/genericode/json/short_name_mixin.rb +1 -1
- data/lib/genericode/key.rb +26 -27
- data/lib/genericode/key_column_ref.rb +7 -8
- data/lib/genericode/key_ref.rb +13 -14
- data/lib/genericode/long_name.rb +11 -11
- data/lib/genericode/mime_typed_uri.rb +5 -6
- data/lib/genericode/row.rb +8 -9
- data/lib/genericode/short_name.rb +7 -7
- data/lib/genericode/simple_code_list.rb +8 -9
- data/lib/genericode/simple_value.rb +3 -4
- data/lib/genericode/value.rb +14 -15
- data/lib/genericode/version.rb +1 -1
- data/lib/genericode.rb +4 -5
- metadata +11 -9
data/lib/genericode/code_list.rb
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
|
|
3
|
+
require 'lutaml/model'
|
|
4
|
+
require_relative 'gc_namespace'
|
|
5
|
+
require 'uri'
|
|
5
6
|
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
8
|
-
require_relative
|
|
9
|
-
require_relative
|
|
10
|
-
require_relative
|
|
7
|
+
require_relative 'annotation'
|
|
8
|
+
require_relative 'column_set'
|
|
9
|
+
require_relative 'column_set_ref'
|
|
10
|
+
require_relative 'identification'
|
|
11
|
+
require_relative 'simple_code_list'
|
|
11
12
|
|
|
12
13
|
module Genericode
|
|
13
14
|
class CodeList < Lutaml::Model::Serializable
|
|
@@ -19,30 +20,30 @@ module Genericode
|
|
|
19
20
|
|
|
20
21
|
def self.from_file(file_path)
|
|
21
22
|
content = File.read(file_path)
|
|
22
|
-
if file_path.end_with?(
|
|
23
|
+
if file_path.end_with?('.gc')
|
|
23
24
|
from_xml(content)
|
|
24
|
-
elsif file_path.end_with?(
|
|
25
|
+
elsif file_path.end_with?('.gcj')
|
|
25
26
|
from_json(content)
|
|
26
27
|
else
|
|
27
|
-
raise Error,
|
|
28
|
+
raise Error, 'Unsupported file format. Expected .gc or .gcj file.'
|
|
28
29
|
end
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
json do
|
|
32
|
-
map
|
|
33
|
-
map
|
|
34
|
-
map
|
|
35
|
-
map
|
|
36
|
-
map
|
|
37
|
-
map
|
|
33
|
+
map 'Annotation', to: :annotation
|
|
34
|
+
map 'Identification', to: :identification
|
|
35
|
+
map 'Columns', to: :column_set, with: { from: :column_set_from_json, to: :column_set_to_json }
|
|
36
|
+
map 'ColumnSetRef', to: :column_set_ref
|
|
37
|
+
map 'Keys', to: :key, delegate: :column_set, with: { from: :key_from_json, to: :key_to_json }
|
|
38
|
+
map 'Codes', to: :simple_code_list, with: { from: :simple_code_list_from_json, to: :simple_code_list_to_json }
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
def column_set_from_json(model, value)
|
|
41
|
-
model.column_set = ColumnSet.of_json({
|
|
42
|
+
model.column_set = ColumnSet.of_json({ 'Column' => value })
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
def column_set_to_json(model, doc)
|
|
45
|
-
doc[
|
|
46
|
+
doc['Columns'] = Column.as_json(model.column_set.column)
|
|
46
47
|
end
|
|
47
48
|
|
|
48
49
|
def key_from_json(model, value)
|
|
@@ -50,7 +51,7 @@ module Genericode
|
|
|
50
51
|
end
|
|
51
52
|
|
|
52
53
|
def key_to_json(model, doc)
|
|
53
|
-
doc[
|
|
54
|
+
doc['Keys'] = Key.as_json(model.column_set.key)
|
|
54
55
|
end
|
|
55
56
|
|
|
56
57
|
def simple_code_list_from_json(model, value)
|
|
@@ -66,25 +67,25 @@ module Genericode
|
|
|
66
67
|
end
|
|
67
68
|
|
|
68
69
|
def simple_code_list_to_json(model, doc)
|
|
69
|
-
doc[
|
|
70
|
+
doc['Codes'] = model.simple_code_list.row.map do |row|
|
|
70
71
|
row.value.to_h { |v| [v.column_ref, v.simple_value.content] }
|
|
71
72
|
end
|
|
72
73
|
end
|
|
73
74
|
|
|
74
75
|
xml do
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
map_element
|
|
79
|
-
map_element
|
|
80
|
-
map_element
|
|
81
|
-
map_element
|
|
82
|
-
map_element
|
|
76
|
+
namespace GcNamespace
|
|
77
|
+
element 'CodeList'
|
|
78
|
+
|
|
79
|
+
map_element 'Annotation', to: :annotation
|
|
80
|
+
map_element 'Identification', to: :identification
|
|
81
|
+
map_element 'ColumnSet', to: :column_set
|
|
82
|
+
map_element 'ColumnSetRef', to: :column_set_ref
|
|
83
|
+
map_element 'SimpleCodeList', to: :simple_code_list
|
|
83
84
|
end
|
|
84
85
|
|
|
85
86
|
def lookup(path)
|
|
86
|
-
parts = path.split(
|
|
87
|
-
conditions = parts[0].split(
|
|
87
|
+
parts = path.split('>')
|
|
88
|
+
conditions = parts[0].split(',').to_h { |c| c.split(':') }
|
|
88
89
|
target_column = parts[1]
|
|
89
90
|
|
|
90
91
|
result = simple_code_list.row.find do |row|
|
|
@@ -108,7 +109,7 @@ module Genericode
|
|
|
108
109
|
result.value.to_h do |v|
|
|
109
110
|
[column_set.column.find do |c|
|
|
110
111
|
c.id == v.column_ref
|
|
111
|
-
end.short_name.content, v.simple_value.content
|
|
112
|
+
end.short_name.content, v.simple_value.content]
|
|
112
113
|
end
|
|
113
114
|
end
|
|
114
115
|
end
|
|
@@ -122,28 +123,28 @@ module Genericode
|
|
|
122
123
|
|
|
123
124
|
# Rule 1: ColumnSet presence
|
|
124
125
|
if column_set.nil? || column_set.column.empty?
|
|
125
|
-
errors << { code:
|
|
126
|
-
message:
|
|
126
|
+
errors << { code: 'MISSING_COLUMN_SET',
|
|
127
|
+
message: 'ColumnSet is missing or empty' }
|
|
127
128
|
end
|
|
128
129
|
|
|
129
130
|
# Rule 2: SimpleCodeList presence
|
|
130
131
|
if simple_code_list.nil? || simple_code_list.row.empty?
|
|
131
|
-
errors << { code:
|
|
132
|
-
message:
|
|
132
|
+
errors << { code: 'MISSING_SIMPLE_CODE_LIST',
|
|
133
|
+
message: 'SimpleCodeList is missing or empty' }
|
|
133
134
|
end
|
|
134
135
|
|
|
135
136
|
# Rule 3: Unique column IDs
|
|
136
137
|
column_ids = column_set&.column&.map(&:id) || []
|
|
137
138
|
if column_ids.uniq.length != column_ids.length
|
|
138
|
-
errors << { code:
|
|
139
|
+
errors << { code: 'DUPLICATE_COLUMN_IDS', message: 'Duplicate column IDs found' }
|
|
139
140
|
end
|
|
140
141
|
|
|
141
142
|
# Rule 4: Verify ColumnRef values
|
|
142
143
|
simple_code_list&.row&.each_with_index do |row, index|
|
|
143
144
|
row.value.each do |value|
|
|
144
145
|
unless column_ids.include?(value.column_ref)
|
|
145
|
-
errors << { code:
|
|
146
|
-
message: "Invalid ColumnRef '#{value.column_ref}' in row #{index + 1}"
|
|
146
|
+
errors << { code: 'INVALID_COLUMN_REF',
|
|
147
|
+
message: "Invalid ColumnRef '#{value.column_ref}' in row #{index + 1}" }
|
|
147
148
|
end
|
|
148
149
|
end
|
|
149
150
|
end
|
|
@@ -155,17 +156,17 @@ module Genericode
|
|
|
155
156
|
end || []).compact
|
|
156
157
|
|
|
157
158
|
if column_values.uniq.length != column_values.length
|
|
158
|
-
errors << { code:
|
|
159
|
+
errors << { code: 'DUPLICATE_VALUES', message: "Duplicate values found in column '#{col.id}'" }
|
|
159
160
|
end
|
|
160
161
|
end
|
|
161
162
|
|
|
162
163
|
# Rule 6: Required column values
|
|
163
|
-
required_columns = column_set&.column&.select { |col| col.use ==
|
|
164
|
+
required_columns = column_set&.column&.select { |col| col.use == 'required' } || []
|
|
164
165
|
simple_code_list&.row&.each_with_index do |row, index|
|
|
165
166
|
required_columns.each do |col|
|
|
166
167
|
unless row.value.any? { |v| v.column_ref == col.id && v.simple_value&.content }
|
|
167
|
-
errors << { code:
|
|
168
|
-
message: "Missing value for required column '#{col.short_name&.content}' in row #{index + 1}"
|
|
168
|
+
errors << { code: 'MISSING_REQUIRED_VALUE',
|
|
169
|
+
message: "Missing value for required column '#{col.short_name&.content}' in row #{index + 1}" }
|
|
169
170
|
end
|
|
170
171
|
end
|
|
171
172
|
end
|
|
@@ -176,49 +177,49 @@ module Genericode
|
|
|
176
177
|
simple_code_list&.row&.each_with_index do |row, index|
|
|
177
178
|
value = row.value.find { |v| v.column_ref == col.id }&.simple_value&.content
|
|
178
179
|
unless value_matches_type?(value, data_type)
|
|
179
|
-
errors << { code:
|
|
180
|
-
message: "Invalid data type for column '#{col.short_name&.content}' in row #{index + 1}"
|
|
180
|
+
errors << { code: 'INVALID_DATA_TYPE',
|
|
181
|
+
message: "Invalid data type for column '#{col.short_name&.content}' in row #{index + 1}" }
|
|
181
182
|
end
|
|
182
183
|
end
|
|
183
184
|
end
|
|
184
185
|
|
|
185
186
|
# Rule 8: Valid canonical URIs
|
|
186
187
|
if identification&.canonical_uri && !valid_uri?(identification.canonical_uri)
|
|
187
|
-
errors << { code:
|
|
188
|
+
errors << { code: 'INVALID_CANONICAL_URI', message: 'Invalid canonical URI' }
|
|
188
189
|
end
|
|
189
190
|
|
|
190
191
|
# Rule 19: Datatype ID validation
|
|
191
192
|
column_set&.column&.each do |col|
|
|
192
193
|
if col.data&.type && !valid_datatype_id?(col.data.type)
|
|
193
|
-
errors << { code:
|
|
194
|
-
message: "Invalid datatype ID for column '#{col.short_name&.content}'"
|
|
194
|
+
errors << { code: 'INVALID_DATATYPE_ID',
|
|
195
|
+
message: "Invalid datatype ID for column '#{col.short_name&.content}'" }
|
|
195
196
|
end
|
|
196
197
|
|
|
197
198
|
# Rule 20 and 22: Complex data validation
|
|
198
|
-
if col.data&.type ==
|
|
199
|
-
errors << { code:
|
|
200
|
-
message: "Invalid complex data configuration for column '#{col.short_name&.content}'"
|
|
199
|
+
if col.data&.type == '*' && col.data&.datatype_library != '*'
|
|
200
|
+
errors << { code: 'INVALID_COMPLEX_DATA',
|
|
201
|
+
message: "Invalid complex data configuration for column '#{col.short_name&.content}'" }
|
|
201
202
|
end
|
|
202
203
|
|
|
203
204
|
# Rule 23: Language attribute validation
|
|
204
205
|
if col.data&.lang && col.data_restrictions&.lang
|
|
205
|
-
errors << { code:
|
|
206
|
-
message: "Duplicate lang attribute for column '#{col.short_name&.content}'"
|
|
206
|
+
errors << { code: 'DUPLICATE_LANG_ATTRIBUTE',
|
|
207
|
+
message: "Duplicate lang attribute for column '#{col.short_name&.content}'" }
|
|
207
208
|
end
|
|
208
209
|
end
|
|
209
210
|
|
|
210
211
|
# Rule 38: Implicit column reference
|
|
211
212
|
simple_code_list&.row&.each_with_index do |row, index|
|
|
212
213
|
unless row.value.all?(&:column_ref)
|
|
213
|
-
errors << { code:
|
|
214
|
+
errors << { code: 'MISSING_COLUMN_REF', message: "Missing explicit column reference in row #{index + 1}" }
|
|
214
215
|
end
|
|
215
216
|
end
|
|
216
217
|
|
|
217
218
|
# Rule 39: ShortName whitespace check
|
|
218
219
|
column_set&.column&.each do |col|
|
|
219
220
|
if col.short_name&.content&.match?(/\s/)
|
|
220
|
-
errors << { code:
|
|
221
|
-
message: "ShortName '#{col.short_name&.content}' contains whitespace"
|
|
221
|
+
errors << { code: 'INVALID_SHORT_NAME',
|
|
222
|
+
message: "ShortName '#{col.short_name&.content}' contains whitespace" }
|
|
222
223
|
end
|
|
223
224
|
end
|
|
224
225
|
|
|
@@ -228,8 +229,8 @@ module Genericode
|
|
|
228
229
|
next unless value.complex_value
|
|
229
230
|
|
|
230
231
|
unless valid_complex_value?(value.complex_value, column_set&.column&.find { |c| c.id == value.column_ref })
|
|
231
|
-
errors << { code:
|
|
232
|
-
message: "Invalid ComplexValue in row #{index + 1}, column '#{value.column_ref}'"
|
|
232
|
+
errors << { code: 'INVALID_COMPLEX_VALUE',
|
|
233
|
+
message: "Invalid ComplexValue in row #{index + 1}, column '#{value.column_ref}'" }
|
|
233
234
|
end
|
|
234
235
|
end
|
|
235
236
|
end
|
|
@@ -241,17 +242,17 @@ module Genericode
|
|
|
241
242
|
|
|
242
243
|
def value_matches_type?(value, type)
|
|
243
244
|
case type
|
|
244
|
-
when
|
|
245
|
+
when 'string'
|
|
245
246
|
true # All values can be considered strings
|
|
246
|
-
when
|
|
247
|
+
when 'integer'
|
|
247
248
|
value.to_i.to_s == value
|
|
248
|
-
when
|
|
249
|
+
when 'decimal'
|
|
249
250
|
begin
|
|
250
251
|
Float(value)
|
|
251
252
|
rescue StandardError
|
|
252
253
|
false
|
|
253
254
|
end
|
|
254
|
-
when
|
|
255
|
+
when 'date'
|
|
255
256
|
begin
|
|
256
257
|
Date.parse(value)
|
|
257
258
|
rescue StandardError
|
|
@@ -273,14 +274,14 @@ module Genericode
|
|
|
273
274
|
def valid_complex_value?(complex_value, column)
|
|
274
275
|
return true unless complex_value && column&.data
|
|
275
276
|
|
|
276
|
-
if column.data.type ==
|
|
277
|
+
if column.data.type == '*'
|
|
277
278
|
true # Any element is allowed
|
|
278
279
|
else
|
|
279
280
|
# Check if the root element name matches the datatype ID
|
|
280
281
|
complex_value.name == column.data.type
|
|
281
282
|
end
|
|
282
283
|
|
|
283
|
-
if column.data.datatype_library ==
|
|
284
|
+
if column.data.datatype_library == '*'
|
|
284
285
|
true # Any namespace is allowed
|
|
285
286
|
else
|
|
286
287
|
# Check if the namespace matches the datatype library
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'lutaml/model'
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
5
|
+
require_relative 'annotation'
|
|
6
|
+
require_relative 'json/canonical_uri_mixin'
|
|
7
7
|
|
|
8
8
|
module Genericode
|
|
9
9
|
class CodeListRef < Lutaml::Model::Serializable
|
|
@@ -15,20 +15,19 @@ module Genericode
|
|
|
15
15
|
attribute :location_uri, :string, collection: true
|
|
16
16
|
|
|
17
17
|
json do
|
|
18
|
-
map
|
|
19
|
-
map
|
|
20
|
-
map
|
|
21
|
-
map
|
|
18
|
+
map 'Annotation', to: :annotation
|
|
19
|
+
map 'CanonicalUri', to: :canonical_uri, with: { from: :canonical_uri_from_json, to: :canonical_uri_to_json }
|
|
20
|
+
map 'CanonicalVersionUri', to: :canonical_version_uri
|
|
21
|
+
map 'LocationUri', to: :location_uri
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
xml do
|
|
25
|
-
|
|
26
|
-
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
|
|
25
|
+
element 'CodeListRef'
|
|
27
26
|
|
|
28
|
-
map_element
|
|
29
|
-
map_element
|
|
30
|
-
map_element
|
|
31
|
-
map_element
|
|
27
|
+
map_element 'Annotation', to: :annotation
|
|
28
|
+
map_element 'CanonicalUri', to: :canonical_uri
|
|
29
|
+
map_element 'CanonicalVersionUri', to: :canonical_version_uri
|
|
30
|
+
map_element 'LocationUri', to: :location_uri
|
|
32
31
|
end
|
|
33
32
|
end
|
|
34
33
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'lutaml/model'
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
8
|
-
require_relative
|
|
5
|
+
require_relative 'annotation'
|
|
6
|
+
require_relative 'code_list_ref'
|
|
7
|
+
require_relative 'code_list_set_ref'
|
|
8
|
+
require_relative 'identification'
|
|
9
9
|
|
|
10
10
|
module Genericode
|
|
11
11
|
class CodeListSet < Lutaml::Model::Serializable
|
|
@@ -16,22 +16,21 @@ module Genericode
|
|
|
16
16
|
attribute :code_list_set_ref, CodeListSetRef, collection: true
|
|
17
17
|
|
|
18
18
|
json do
|
|
19
|
-
map
|
|
20
|
-
map
|
|
21
|
-
map
|
|
22
|
-
map
|
|
23
|
-
map
|
|
19
|
+
map 'Annotation', to: :annotation
|
|
20
|
+
map 'Identification', to: :identification
|
|
21
|
+
map 'CodeListRef', to: :code_list_ref
|
|
22
|
+
map 'CodeListSet', to: :code_list_set
|
|
23
|
+
map 'CodeListSetRef', to: :code_list_set_ref
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
xml do
|
|
27
|
-
|
|
28
|
-
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
|
|
27
|
+
element 'CodeListSet'
|
|
29
28
|
|
|
30
|
-
map_element
|
|
31
|
-
map_element
|
|
32
|
-
map_element
|
|
33
|
-
map_element
|
|
34
|
-
map_element
|
|
29
|
+
map_element 'Annotation', to: :annotation
|
|
30
|
+
map_element 'Identification', to: :identification
|
|
31
|
+
map_element 'CodeListRef', to: :code_list_ref
|
|
32
|
+
map_element 'CodeListSet', to: :code_list_set
|
|
33
|
+
map_element 'CodeListSetRef', to: :code_list_set_ref
|
|
35
34
|
end
|
|
36
35
|
|
|
37
36
|
def validate_verbose
|
|
@@ -40,19 +39,19 @@ module Genericode
|
|
|
40
39
|
# Rule 47: CodeListSet reference validation
|
|
41
40
|
code_list_set_ref&.each do |ref|
|
|
42
41
|
unless valid_uri?(ref.canonical_uri) && valid_uri?(ref.canonical_version_uri)
|
|
43
|
-
errors << { code:
|
|
42
|
+
errors << { code: 'INVALID_CODELIST_SET_REF', message: 'Invalid CodeListSet reference URI' }
|
|
44
43
|
end
|
|
45
44
|
end
|
|
46
45
|
|
|
47
46
|
# Rule 48-51: URI validations
|
|
48
47
|
[canonical_uri, canonical_version_uri].each do |uri|
|
|
49
|
-
errors << { code:
|
|
48
|
+
errors << { code: 'INVALID_URI', message: "Invalid URI: #{uri}" } unless valid_uri?(uri)
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
# Rule 52-53: LocationUri validation
|
|
53
52
|
location_uri&.each do |uri|
|
|
54
53
|
unless valid_genericode_uri?(uri)
|
|
55
|
-
errors << { code:
|
|
54
|
+
errors << { code: 'INVALID_LOCATION_URI', message: "Invalid LocationUri: #{uri}" }
|
|
56
55
|
end
|
|
57
56
|
end
|
|
58
57
|
|
|
@@ -68,7 +67,7 @@ module Genericode
|
|
|
68
67
|
def valid_genericode_uri?(uri)
|
|
69
68
|
# Add logic to check if the URI points to a valid genericode document
|
|
70
69
|
# This might involve making an HTTP request or checking file extensions
|
|
71
|
-
uri.end_with?(
|
|
70
|
+
uri.end_with?('.gc', '.gcj')
|
|
72
71
|
end
|
|
73
72
|
end
|
|
74
73
|
end
|
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'lutaml/model'
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
5
|
+
require_relative 'annotation'
|
|
6
|
+
require_relative 'canonical_uri'
|
|
7
|
+
require_relative 'json/canonical_uri_mixin'
|
|
8
8
|
|
|
9
9
|
module Genericode
|
|
10
10
|
class CodeListSetRef < Lutaml::Model::Serializable
|
|
11
11
|
include Json::CanonicalUriMixin
|
|
12
|
+
|
|
12
13
|
attribute :annotation, Annotation
|
|
13
14
|
attribute :canonical_uri, CanonicalUri
|
|
14
15
|
attribute :canonical_version_uri, :string
|
|
15
16
|
attribute :location_uri, :string, collection: true
|
|
16
17
|
|
|
17
18
|
json do
|
|
18
|
-
map
|
|
19
|
-
map
|
|
20
|
-
map
|
|
21
|
-
map
|
|
19
|
+
map 'Annotation', to: :annotation
|
|
20
|
+
map 'CanonicalUri', to: :canonical_uri, with: { from: :canonical_uri_from_json, to: :canonical_uri_to_json }
|
|
21
|
+
map 'CanonicalVersionUri', to: :canonical_version_uri
|
|
22
|
+
map 'LocationUri', to: :location_uri
|
|
22
23
|
end
|
|
23
24
|
|
|
24
25
|
xml do
|
|
25
|
-
|
|
26
|
-
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
|
|
26
|
+
element 'CodeListSetRef'
|
|
27
27
|
|
|
28
|
-
map_element
|
|
29
|
-
map_element
|
|
30
|
-
map_element
|
|
31
|
-
map_element
|
|
28
|
+
map_element 'Annotation', to: :annotation
|
|
29
|
+
map_element 'CanonicalUri', to: :canonical_uri
|
|
30
|
+
map_element 'CanonicalVersionUri', to: :canonical_version_uri
|
|
31
|
+
map_element 'LocationUri', to: :location_uri
|
|
32
32
|
end
|
|
33
33
|
end
|
|
34
34
|
end
|
data/lib/genericode/column.rb
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'lutaml/model'
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
7
|
-
require_relative
|
|
8
|
-
require_relative
|
|
9
|
-
require_relative
|
|
10
|
-
require_relative
|
|
11
|
-
require_relative
|
|
12
|
-
require_relative
|
|
5
|
+
require_relative 'annotation'
|
|
6
|
+
require_relative 'data'
|
|
7
|
+
require_relative 'canonical_uri'
|
|
8
|
+
require_relative 'long_name'
|
|
9
|
+
require_relative 'short_name'
|
|
10
|
+
require_relative 'json/short_name_mixin'
|
|
11
|
+
require_relative 'json/canonical_uri_mixin'
|
|
12
|
+
require_relative 'utils'
|
|
13
13
|
|
|
14
14
|
module Genericode
|
|
15
15
|
class Column < Lutaml::Model::Serializable
|
|
@@ -17,7 +17,7 @@ module Genericode
|
|
|
17
17
|
include Json::ShortNameMixin
|
|
18
18
|
|
|
19
19
|
attribute :id, :string
|
|
20
|
-
attribute :use, :string, default: -> {
|
|
20
|
+
attribute :use, :string, default: -> { 'optional' }
|
|
21
21
|
attribute :annotation, Annotation
|
|
22
22
|
attribute :short_name, ShortName
|
|
23
23
|
attribute :long_name, LongName, collection: true, initialize_empty: true
|
|
@@ -26,23 +26,23 @@ module Genericode
|
|
|
26
26
|
attribute :data, Data
|
|
27
27
|
|
|
28
28
|
json do
|
|
29
|
-
map
|
|
30
|
-
map
|
|
31
|
-
map
|
|
32
|
-
map
|
|
33
|
-
map
|
|
34
|
-
map
|
|
35
|
-
map
|
|
36
|
-
map
|
|
37
|
-
map
|
|
29
|
+
map 'Required', to: :use, with: { from: :use_from_json, to: :use_to_json }
|
|
30
|
+
map 'Id', to: :id
|
|
31
|
+
map 'Annotation', to: :annotation
|
|
32
|
+
map 'ShortName', to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
|
|
33
|
+
map 'LongName', to: :long_name, with: { from: :long_name_from_json, to: :long_name_to_json }
|
|
34
|
+
map 'CanonicalUri', to: :canonical_uri, with: { from: :canonical_uri_from_json, to: :canonical_uri_to_json }
|
|
35
|
+
map 'CanonicalVersionUri', to: :canonical_version_uri
|
|
36
|
+
map 'DataType', to: :type, delegate: :data
|
|
37
|
+
map 'DataLanguage', to: :lang, delegate: :data
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def use_from_json(model, value)
|
|
41
|
-
model.use = value ==
|
|
41
|
+
model.use = value == 'true' ? 'required' : 'optional'
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
def use_to_json(model, doc)
|
|
45
|
-
doc[
|
|
45
|
+
doc['Required'] = 'true' if model.use == 'required'
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def long_name_from_json(model, value)
|
|
@@ -52,21 +52,20 @@ module Genericode
|
|
|
52
52
|
def long_name_to_json(model, doc)
|
|
53
53
|
return if model.long_name.nil? || model.long_name.empty?
|
|
54
54
|
|
|
55
|
-
doc[
|
|
55
|
+
doc['LongName'] = LongName.as_json(Utils.one_or_all(model.long_name))
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
xml do
|
|
59
|
-
|
|
60
|
-
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
|
|
59
|
+
element 'Column'
|
|
61
60
|
|
|
62
|
-
map_attribute
|
|
63
|
-
map_attribute
|
|
64
|
-
map_element
|
|
65
|
-
map_element
|
|
66
|
-
map_element
|
|
67
|
-
map_element
|
|
68
|
-
map_element
|
|
69
|
-
map_element
|
|
61
|
+
map_attribute 'Id', to: :id
|
|
62
|
+
map_attribute 'Use', to: :use
|
|
63
|
+
map_element 'Annotation', to: :annotation
|
|
64
|
+
map_element 'ShortName', to: :short_name
|
|
65
|
+
map_element 'LongName', to: :long_name
|
|
66
|
+
map_element 'CanonicalUri', to: :canonical_uri
|
|
67
|
+
map_element 'CanonicalVersionUri', to: :canonical_version_uri
|
|
68
|
+
map_element 'Data', to: :data
|
|
70
69
|
end
|
|
71
70
|
end
|
|
72
71
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'lutaml/model'
|
|
4
4
|
|
|
5
|
-
require_relative
|
|
6
|
-
require_relative
|
|
5
|
+
require_relative 'annotation'
|
|
6
|
+
require_relative 'data_restrictions'
|
|
7
7
|
|
|
8
8
|
module Genericode
|
|
9
9
|
class ColumnRef < Lutaml::Model::Serializable
|
|
@@ -16,26 +16,25 @@ module Genericode
|
|
|
16
16
|
attribute :data, DataRestrictions
|
|
17
17
|
|
|
18
18
|
json do
|
|
19
|
-
map
|
|
20
|
-
map
|
|
21
|
-
map
|
|
22
|
-
map
|
|
23
|
-
map
|
|
24
|
-
map
|
|
25
|
-
map
|
|
19
|
+
map 'Id', to: :id
|
|
20
|
+
map 'ExternalRef', to: :external_ref
|
|
21
|
+
map 'Use', to: :use
|
|
22
|
+
map 'Annotation', to: :annotation
|
|
23
|
+
map 'CanonicalVersionUri', to: :canonical_version_uri
|
|
24
|
+
map 'LocationUri', to: :location_uri
|
|
25
|
+
map 'Data', to: :data
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
xml do
|
|
29
|
-
|
|
30
|
-
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
|
|
29
|
+
element 'ColumnRef'
|
|
31
30
|
|
|
32
|
-
map_attribute
|
|
33
|
-
map_attribute
|
|
34
|
-
map_attribute
|
|
35
|
-
map_element
|
|
36
|
-
map_element
|
|
37
|
-
map_element
|
|
38
|
-
map_element
|
|
31
|
+
map_attribute 'Id', to: :id
|
|
32
|
+
map_attribute 'ExternalRef', to: :external_ref
|
|
33
|
+
map_attribute 'Use', to: :use
|
|
34
|
+
map_element 'Annotation', to: :annotation
|
|
35
|
+
map_element 'CanonicalVersionUri', to: :canonical_version_uri
|
|
36
|
+
map_element 'LocationUri', to: :location_uri
|
|
37
|
+
map_element 'Data', to: :data
|
|
39
38
|
end
|
|
40
39
|
end
|
|
41
40
|
end
|