genericode 0.1.0 → 0.1.2
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 +27 -1
- data/.rubocop_todo.yml +66 -0
- data/README.adoc +282 -0
- data/exe/genericode +7 -0
- data/lib/genericode/agency.rb +25 -5
- data/lib/genericode/annotation.rb +10 -4
- data/lib/genericode/any_other_content.rb +2 -2
- data/lib/genericode/any_other_language_content.rb +3 -3
- data/lib/genericode/canonical_uri.rb +32 -0
- data/lib/genericode/cli/code_lister.rb +67 -0
- data/lib/genericode/cli/code_lookup.rb +22 -0
- data/lib/genericode/cli/commands.rb +76 -0
- data/lib/genericode/cli/converter.rb +35 -0
- data/lib/genericode/cli/validator.rb +21 -0
- data/lib/genericode/cli.rb +8 -0
- data/lib/genericode/code_list.rb +257 -9
- data/lib/genericode/code_list_ref.rb +9 -6
- data/lib/genericode/code_list_set.rb +39 -2
- data/lib/genericode/code_list_set_ref.rb +9 -6
- data/lib/genericode/column.rb +37 -11
- data/lib/genericode/column_ref.rb +7 -7
- data/lib/genericode/column_set.rb +3 -3
- data/lib/genericode/column_set_ref.rb +4 -4
- data/lib/genericode/data.rb +5 -5
- data/lib/genericode/data_restrictions.rb +3 -3
- data/lib/genericode/datatype_facet.rb +10 -7
- data/lib/genericode/general_identifier.rb +6 -6
- data/lib/genericode/identification.rb +53 -11
- data/lib/genericode/json/canonical_uri_mixin.rb +17 -0
- data/lib/genericode/json/short_name_mixin.rb +17 -0
- data/lib/genericode/key.rb +34 -9
- data/lib/genericode/key_column_ref.rb +3 -3
- data/lib/genericode/key_ref.rb +6 -6
- data/lib/genericode/long_name.rb +17 -7
- data/lib/genericode/mime_typed_uri.rb +5 -5
- data/lib/genericode/row.rb +2 -2
- data/lib/genericode/short_name.rb +10 -5
- data/lib/genericode/simple_code_list.rb +2 -2
- data/lib/genericode/simple_value.rb +3 -3
- data/lib/genericode/utils.rb +50 -0
- data/lib/genericode/value.rb +5 -4
- data/lib/genericode/version.rb +1 -1
- data/lib/genericode.rb +12 -0
- data/oasis-reqs-implemented.md +31 -0
- data/oasis-requirements-1.0.md +56 -0
- metadata +28 -54
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
|
7
7
|
module Genericode
|
8
|
-
class ColumnSetRef <
|
8
|
+
class ColumnSetRef < Lutaml::Model::Serializable
|
9
9
|
attribute :annotation, Annotation
|
10
|
-
attribute :canonical_version_uri,
|
11
|
-
attribute :location_uri,
|
10
|
+
attribute :canonical_version_uri, :string
|
11
|
+
attribute :location_uri, :string, collection: true
|
12
12
|
|
13
13
|
json do
|
14
14
|
map "Annotation", to: :annotation
|
data/lib/genericode/data.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
require_relative "datatype_facet"
|
7
7
|
|
8
8
|
module Genericode
|
9
|
-
class Data <
|
10
|
-
attribute :type,
|
11
|
-
attribute :datatype_library,
|
12
|
-
attribute :lang,
|
9
|
+
class Data < Lutaml::Model::Serializable
|
10
|
+
attribute :type, :string
|
11
|
+
attribute :datatype_library, :string
|
12
|
+
attribute :lang, :string
|
13
13
|
attribute :annotation, Annotation
|
14
14
|
attribute :parameter, DatatypeFacet, collection: true
|
15
15
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "datatype_facet"
|
6
6
|
|
7
7
|
module Genericode
|
8
|
-
class DataRestrictions <
|
9
|
-
attribute :lang,
|
8
|
+
class DataRestrictions < Lutaml::Model::Serializable
|
9
|
+
attribute :lang, :string
|
10
10
|
attribute :parameter, DatatypeFacet, collection: true
|
11
11
|
|
12
12
|
json do
|
@@ -1,17 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
|
+
require_relative "json/short_name_mixin"
|
4
5
|
|
5
6
|
module Genericode
|
6
|
-
class DatatypeFacet <
|
7
|
-
|
8
|
-
|
9
|
-
attribute :
|
7
|
+
class DatatypeFacet < Lutaml::Model::Serializable
|
8
|
+
include Json::ShortNameMixin
|
9
|
+
|
10
|
+
attribute :content, :string
|
11
|
+
attribute :short_name, :string
|
12
|
+
attribute :long_name, :string
|
10
13
|
|
11
14
|
json do
|
12
|
-
map "
|
13
|
-
map "ShortName", to: :short_name
|
15
|
+
map "ShortName", to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
|
14
16
|
map "LongName", to: :long_name
|
17
|
+
map "_", to: :content
|
15
18
|
end
|
16
19
|
|
17
20
|
xml do
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
module Genericode
|
6
|
-
class GeneralIdentifier <
|
7
|
-
attribute :content,
|
8
|
-
attribute :identifier,
|
9
|
-
attribute :lang,
|
6
|
+
class GeneralIdentifier < Lutaml::Model::Serializable
|
7
|
+
attribute :content, :string
|
8
|
+
attribute :identifier, :string
|
9
|
+
attribute :lang, :string
|
10
10
|
|
11
11
|
json do
|
12
|
-
map "_", to: :content
|
13
12
|
map "Identifier", to: :identifier
|
14
13
|
map "lang", to: :lang
|
14
|
+
map "_", to: :content
|
15
15
|
end
|
16
16
|
|
17
17
|
xml do
|
@@ -1,34 +1,76 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "agency"
|
6
6
|
require_relative "long_name"
|
7
7
|
require_relative "mime_typed_uri"
|
8
|
+
require_relative "canonical_uri"
|
8
9
|
require_relative "short_name"
|
10
|
+
require_relative "json/short_name_mixin"
|
11
|
+
require_relative "json/canonical_uri_mixin"
|
12
|
+
require_relative "utils"
|
9
13
|
|
10
14
|
module Genericode
|
11
|
-
class Identification <
|
15
|
+
class Identification < Lutaml::Model::Serializable
|
16
|
+
include Json::CanonicalUriMixin
|
17
|
+
include Json::ShortNameMixin
|
18
|
+
|
12
19
|
attribute :short_name, ShortName
|
13
20
|
attribute :long_name, LongName, collection: true
|
14
|
-
attribute :version,
|
15
|
-
attribute :canonical_uri,
|
16
|
-
attribute :canonical_version_uri,
|
17
|
-
attribute :location_uri,
|
21
|
+
attribute :version, :string
|
22
|
+
attribute :canonical_uri, CanonicalUri
|
23
|
+
attribute :canonical_version_uri, :string
|
24
|
+
attribute :location_uri, :string, collection: true
|
18
25
|
attribute :alternate_format_location_uri, MimeTypedUri, collection: true
|
19
26
|
attribute :agency, Agency
|
20
27
|
|
21
28
|
json do
|
22
|
-
map "ShortName", to: :short_name
|
23
|
-
map "LongName", to: :long_name
|
29
|
+
map "ShortName", to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
|
30
|
+
map "LongName", to: :long_name, with: { from: :long_name_from_json, to: :long_name_to_json }
|
24
31
|
map "Version", to: :version
|
25
|
-
map "CanonicalUri", to: :canonical_uri
|
32
|
+
map "CanonicalUri", to: :canonical_uri, with: { from: :canonical_uri_from_json, to: :canonical_uri_to_json }
|
26
33
|
map "CanonicalVersionUri", to: :canonical_version_uri
|
27
|
-
map "LocationUri", to: :location_uri
|
28
|
-
map "AlternateFormatLocationUri", to: :alternate_format_location_uri
|
34
|
+
map "LocationUri", to: :location_uri, with: { from: :location_uri_from_json, to: :location_uri_to_json }
|
35
|
+
map "AlternateFormatLocationUri", to: :alternate_format_location_uri,
|
36
|
+
with: { from: :alternate_format_location_uri_from_json,
|
37
|
+
to: :alternate_format_location_uri_to_json, }
|
29
38
|
map "Agency", to: :agency
|
30
39
|
end
|
31
40
|
|
41
|
+
def long_name_from_json(model, value)
|
42
|
+
model.long_name = LongName.of_json(value)
|
43
|
+
end
|
44
|
+
|
45
|
+
def long_name_to_json(model, doc)
|
46
|
+
return if model.long_name.empty?
|
47
|
+
|
48
|
+
doc["LongName"] = LongName.as_json(model.long_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
def location_uri_from_json(model, value)
|
52
|
+
# model.location_uri = Shale::Type::String.of_json(Utils.array_wrap(value))
|
53
|
+
model.location_uri = Utils.array_wrap(value).map do |val|
|
54
|
+
Lutaml::Model::Type::String.cast(val)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def location_uri_to_json(model, doc)
|
59
|
+
return if model.location_uri.empty?
|
60
|
+
|
61
|
+
doc["LocationUri"] = Lutaml::Model::Type::String.cast(Utils.one_or_all(model.location_uri))
|
62
|
+
end
|
63
|
+
|
64
|
+
def alternate_format_location_uri_from_json(model, value)
|
65
|
+
model.alternate_format_location_uri = MimeTypedUri.of_json(Utils.array_wrap(value))
|
66
|
+
end
|
67
|
+
|
68
|
+
def alternate_format_location_uri_to_json(model, doc)
|
69
|
+
return if model.alternate_format_location_uri.empty?
|
70
|
+
|
71
|
+
doc["AlternateFormatLocationUri"] = MimeTypedUri.as_json(Utils.one_or_all(model.alternate_format_location_uri))
|
72
|
+
end
|
73
|
+
|
32
74
|
xml do
|
33
75
|
root "Identification"
|
34
76
|
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Genericode
|
4
|
+
module Json
|
5
|
+
module CanonicalUriMixin
|
6
|
+
def canonical_uri_from_json(model, value)
|
7
|
+
model.canonical_uri = CanonicalUri.new(content: value) if value
|
8
|
+
end
|
9
|
+
|
10
|
+
def canonical_uri_to_json(model, doc)
|
11
|
+
return if model.canonical_uri.nil?
|
12
|
+
|
13
|
+
doc["CanonicalUri"] = model.canonical_uri&.content
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Genericode
|
4
|
+
module Json
|
5
|
+
module ShortNameMixin
|
6
|
+
def short_name_from_json(model, value)
|
7
|
+
model.short_name = ShortName.new(content: value) if value
|
8
|
+
end
|
9
|
+
|
10
|
+
def short_name_to_json(model, doc)
|
11
|
+
return if model.short_name.nil?
|
12
|
+
|
13
|
+
doc["ShortName"] = model.short_name.content
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/genericode/key.rb
CHANGED
@@ -1,30 +1,55 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
require_relative "key_column_ref"
|
7
|
+
require_relative "canonical_uri"
|
7
8
|
require_relative "long_name"
|
8
9
|
require_relative "short_name"
|
10
|
+
require_relative "json/short_name_mixin"
|
11
|
+
require_relative "json/canonical_uri_mixin"
|
12
|
+
require_relative "utils"
|
9
13
|
|
10
14
|
module Genericode
|
11
|
-
class Key <
|
12
|
-
|
15
|
+
class Key < Lutaml::Model::Serializable
|
16
|
+
include Json::CanonicalUriMixin
|
17
|
+
include Json::ShortNameMixin
|
18
|
+
|
19
|
+
attribute :id, :string
|
13
20
|
attribute :annotation, Annotation
|
14
21
|
attribute :short_name, ShortName
|
15
22
|
attribute :long_name, LongName, collection: true
|
16
|
-
attribute :canonical_uri,
|
17
|
-
attribute :canonical_version_uri,
|
23
|
+
attribute :canonical_uri, CanonicalUri
|
24
|
+
attribute :canonical_version_uri, :string
|
18
25
|
attribute :column_ref, KeyColumnRef, collection: true
|
19
26
|
|
20
27
|
json do
|
21
28
|
map "Id", to: :id
|
22
29
|
map "Annotation", to: :annotation
|
23
|
-
map "ShortName", to: :short_name
|
24
|
-
map "LongName", to: :long_name
|
25
|
-
map "CanonicalUri", to: :canonical_uri
|
30
|
+
map "ShortName", to: :short_name, with: { from: :short_name_from_json, to: :short_name_to_json }
|
31
|
+
map "LongName", to: :long_name, with: { from: :long_name_from_json, to: :long_name_to_json }
|
32
|
+
map "CanonicalUri", to: :canonical_uri, with: { from: :canonical_uri_from_json, to: :canonical_uri_to_json }
|
26
33
|
map "CanonicalVersionUri", to: :canonical_version_uri
|
27
|
-
map "ColumnRef", to: :column_ref
|
34
|
+
map "ColumnRef", to: :column_ref, with: { from: :column_ref_from_json, to: :column_ref_to_json }
|
35
|
+
end
|
36
|
+
|
37
|
+
def long_name_from_json(model, value)
|
38
|
+
model.long_name = LongName.of_json(value)
|
39
|
+
end
|
40
|
+
|
41
|
+
def long_name_to_json(model, doc)
|
42
|
+
return if model.long_name.empty?
|
43
|
+
|
44
|
+
doc["LongName"] = LongName.as_json(model.long_name)
|
45
|
+
end
|
46
|
+
|
47
|
+
def column_ref_from_json(model, value)
|
48
|
+
model.column_ref = Utils.array_wrap(value).map { |n| KeyColumnRef.new(ref: n) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def column_ref_to_json(model, doc)
|
52
|
+
doc["ColumnRef"] = Utils.one_or_all(model.column_ref.map(&:ref))
|
28
53
|
end
|
29
54
|
|
30
55
|
xml do
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
|
7
7
|
module Genericode
|
8
|
-
class KeyColumnRef <
|
9
|
-
attribute :ref,
|
8
|
+
class KeyColumnRef < Lutaml::Model::Serializable
|
9
|
+
attribute :ref, :string
|
10
10
|
attribute :annotation, Annotation
|
11
11
|
|
12
12
|
json do
|
data/lib/genericode/key_ref.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
|
7
7
|
module Genericode
|
8
|
-
class KeyRef <
|
9
|
-
attribute :id,
|
10
|
-
attribute :external_ref,
|
8
|
+
class KeyRef < Lutaml::Model::Serializable
|
9
|
+
attribute :id, :string
|
10
|
+
attribute :external_ref, :string
|
11
11
|
attribute :annotation, Annotation
|
12
|
-
attribute :canonical_version_uri,
|
13
|
-
attribute :location_uri,
|
12
|
+
attribute :canonical_version_uri, :string
|
13
|
+
attribute :location_uri, :string, collection: true
|
14
14
|
|
15
15
|
json do
|
16
16
|
map "Id", to: :id
|
data/lib/genericode/long_name.rb
CHANGED
@@ -1,17 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
module Genericode
|
6
|
-
class LongName <
|
7
|
-
attribute :content,
|
8
|
-
attribute :identifier,
|
9
|
-
attribute :lang,
|
6
|
+
class LongName < Lutaml::Model::Serializable
|
7
|
+
attribute :content, :string
|
8
|
+
attribute :identifier, :string
|
9
|
+
attribute :lang, :string
|
10
10
|
|
11
11
|
json do
|
12
|
-
map "_", to: :content
|
13
12
|
map "Identifier", to: :identifier
|
14
|
-
map "
|
13
|
+
map "http://www.w3.org/XML/1998/namespace", to: :lang, with: { from: :lang_from_json, to: :lang_to_json }
|
14
|
+
map "_", to: :content
|
15
|
+
end
|
16
|
+
|
17
|
+
def lang_from_json(model, value)
|
18
|
+
model.lang = value["lang"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def lang_to_json(model, doc)
|
22
|
+
return if model.lang.nil?
|
23
|
+
|
24
|
+
doc["http://www.w3.org/XML/1998/namespace"] = { "lang" => model.lang }
|
15
25
|
end
|
16
26
|
|
17
27
|
xml do
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
module Genericode
|
6
|
-
class MimeTypedUri <
|
7
|
-
attribute :content,
|
8
|
-
attribute :mime_type,
|
6
|
+
class MimeTypedUri < Lutaml::Model::Serializable
|
7
|
+
attribute :content, :string
|
8
|
+
attribute :mime_type, :string
|
9
9
|
|
10
10
|
json do
|
11
|
-
map "_", to: :content
|
12
11
|
map "MimeType", to: :mime_type
|
12
|
+
map "_", to: :content
|
13
13
|
end
|
14
14
|
|
15
15
|
xml do
|
data/lib/genericode/row.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
require_relative "value"
|
7
7
|
|
8
8
|
module Genericode
|
9
|
-
class Row <
|
9
|
+
class Row < Lutaml::Model::Serializable
|
10
10
|
attribute :annotation, Annotation
|
11
11
|
attribute :value, Value, collection: true
|
12
12
|
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
module Genericode
|
6
|
-
class ShortName <
|
7
|
-
attribute :content,
|
8
|
-
attribute :lang,
|
6
|
+
class ShortName < Lutaml::Model::Serializable
|
7
|
+
attribute :content, :string
|
8
|
+
attribute :lang, :string
|
9
9
|
|
10
10
|
json do
|
11
|
-
map "_", to: :content
|
12
11
|
map "lang", to: :lang
|
12
|
+
map "_", to: :content
|
13
13
|
end
|
14
14
|
|
15
15
|
xml do
|
@@ -19,5 +19,10 @@ module Genericode
|
|
19
19
|
map_content to: :content
|
20
20
|
map_attribute "lang", to: :lang, prefix: "xml", namespace: "http://www.w3.org/XML/1998/namespace"
|
21
21
|
end
|
22
|
+
|
23
|
+
# Rule 39: Must not contain whitespace characters
|
24
|
+
def valid?
|
25
|
+
!content.match(/\s/)
|
26
|
+
end
|
22
27
|
end
|
23
28
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
require_relative "row"
|
7
7
|
|
8
8
|
module Genericode
|
9
|
-
class SimpleCodeList <
|
9
|
+
class SimpleCodeList < Lutaml::Model::Serializable
|
10
10
|
attribute :annotation, Annotation
|
11
11
|
attribute :row, Row, collection: true
|
12
12
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
module Genericode
|
6
|
-
class SimpleValue <
|
7
|
-
attribute :content,
|
6
|
+
class SimpleValue < Lutaml::Model::Serializable
|
7
|
+
attribute :content, :string
|
8
8
|
|
9
9
|
json do
|
10
10
|
map "_", to: :content
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Genericode
|
4
|
+
# Utility functions
|
5
|
+
#
|
6
|
+
# @api private
|
7
|
+
module Utils
|
8
|
+
# Wraps object in an array unless it is already an array (or array-like)
|
9
|
+
#
|
10
|
+
# @param [Object] object
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# Utils.array_wrap(nil) # => []
|
14
|
+
# Utils.array_wrap([1, 2, 3]) # => [1, 2, 3]
|
15
|
+
# Utils.array_wrap(0) # => [0]
|
16
|
+
# Utils.array_wrap(foo: :bar) # => [{:foo=>:bar}]
|
17
|
+
#
|
18
|
+
# @return [Array] An array containing the object. If the object is nil,
|
19
|
+
# returns an empty array. If the object responds to `to_ary`, converts it
|
20
|
+
# to an array. Otherwise, wraps the object in an array.
|
21
|
+
#
|
22
|
+
# @api private
|
23
|
+
def self.array_wrap(object)
|
24
|
+
if object.nil?
|
25
|
+
[]
|
26
|
+
elsif object.respond_to?(:to_ary)
|
27
|
+
object.to_ary
|
28
|
+
else
|
29
|
+
[object]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Returns either the only element of the array or the array itself
|
34
|
+
#
|
35
|
+
# @param [Array] array
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# Utils.one_or_all([0]) # => 0
|
39
|
+
# Utils.one_or_all([1, 2, 3]) # => [1, 2, 3]
|
40
|
+
# Utils.one_or_all([]) # => []
|
41
|
+
#
|
42
|
+
# @return [Object, Array] The first element of the array if the array has
|
43
|
+
# only one element, otherwise returns the entire array.
|
44
|
+
#
|
45
|
+
# @api private
|
46
|
+
def self.one_or_all(array)
|
47
|
+
array.one? ? array.first : array
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/genericode/value.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "lutaml/model"
|
4
4
|
|
5
5
|
require_relative "annotation"
|
6
6
|
require_relative "any_other_content"
|
7
7
|
require_relative "simple_value"
|
8
|
+
require_relative "column_ref"
|
8
9
|
|
9
10
|
module Genericode
|
10
|
-
class Value <
|
11
|
-
attribute :column_ref,
|
11
|
+
class Value < Lutaml::Model::Serializable
|
12
|
+
attribute :column_ref, :string
|
12
13
|
attribute :annotation, Annotation
|
13
14
|
attribute :simple_value, SimpleValue
|
14
15
|
attribute :complex_value, AnyOtherContent
|
@@ -24,7 +25,7 @@ module Genericode
|
|
24
25
|
root "Value"
|
25
26
|
namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"
|
26
27
|
|
27
|
-
map_attribute "ColumnRef", to: :column_ref
|
28
|
+
map_attribute "ColumnRef", to: :column_ref, prefix: nil, namespace: nil
|
28
29
|
map_element "Annotation", to: :annotation, prefix: nil, namespace: nil
|
29
30
|
map_element "SimpleValue", to: :simple_value, prefix: nil, namespace: nil
|
30
31
|
map_element "ComplexValue", to: :complex_value, prefix: nil, namespace: nil
|
data/lib/genericode/version.rb
CHANGED
data/lib/genericode.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "lutaml/model"
|
4
|
+
|
5
|
+
Lutaml::Model::Config.configure do |config|
|
6
|
+
require "lutaml/model/xml_adapter/nokogiri_adapter"
|
7
|
+
config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
|
8
|
+
end
|
9
|
+
|
3
10
|
require_relative "genericode/version"
|
4
11
|
require_relative "genericode/code_list"
|
5
12
|
|
6
13
|
module Genericode
|
7
14
|
class Error < StandardError; end
|
15
|
+
|
16
|
+
def self.validate(file_path)
|
17
|
+
code_list = CodeList.from_file(file_path)
|
18
|
+
code_list.validate_verbose
|
19
|
+
end
|
8
20
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
| Rule | Supported | Implementation |
|
2
|
+
|------|-----------|----------------|
|
3
|
+
| Rule 1 | Yes | Implemented in `CodeList#validate_verbose` method |
|
4
|
+
| Rule 2 | No | Not applicable (xml:base) |
|
5
|
+
| Rule 3 | No | Not implemented (external reference validation) |
|
6
|
+
| Rule 4 | Yes | Implemented in `CodeList#validate_verbose` method (valid_uri? check) |
|
7
|
+
| Rule 5 | No | Not applicable (runtime behavior) |
|
8
|
+
| Rule 6 | Yes | Implemented in `CodeList#validate_verbose` method (valid_uri? check) |
|
9
|
+
| Rule 7 | No | Not applicable (runtime behavior) |
|
10
|
+
| Rule 8 | No | Not implemented (external reference validation) |
|
11
|
+
| Rule 9 | No | Not applicable (runtime behavior) |
|
12
|
+
| Rule 10-18 | No | Not applicable (xml:base) |
|
13
|
+
| Rule 19 | No | Not implemented (datatype ID validation) |
|
14
|
+
| Rule 20 | No | Not implemented (complex data validation) |
|
15
|
+
| Rule 21 | No | Not applicable (runtime behavior) |
|
16
|
+
| Rule 22 | No | Not implemented (complex data validation) |
|
17
|
+
| Rule 23 | No | Not implemented (language attribute validation) |
|
18
|
+
| Rule 24 | No | Not applicable (external reference format) |
|
19
|
+
| Rule 25 | Yes | Implemented in `CodeList#validate_verbose` method (valid_uri? check) |
|
20
|
+
| Rule 26-33 | No | Not applicable (runtime behavior or URI usage) |
|
21
|
+
| Rule 34 | Yes | Implemented in `CodeList#validate_verbose` method |
|
22
|
+
| Rule 35-36 | No | Not applicable (external reference validation or xml:base) |
|
23
|
+
| Rule 37 | Yes | Implemented in `CodeList#validate_verbose` method |
|
24
|
+
| Rule 38 | No | Not implemented (implicit column reference) |
|
25
|
+
| Rule 39 | No | Not implemented (ShortName whitespace check) |
|
26
|
+
| Rule 40 | No | Not applicable (runtime behavior) |
|
27
|
+
| Rule 41 | Yes | Partially implemented in `CodeList#validate_verbose` method (value_matches_type? check) |
|
28
|
+
| Rule 42-43 | No | Not implemented (ComplexValue validation) |
|
29
|
+
| Rule 44 | Yes | Implemented in `CodeList#validate_verbose` method (valid_uri? check) |
|
30
|
+
| Rule 45-46 | No | Not applicable (runtime behavior) |
|
31
|
+
| Rule 47-54 | No | Not implemented (CodeListSet validation) |
|