unitsdb 1.0.0 → 2.0.1

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +3 -0
  3. data/.rspec +2 -1
  4. data/.rubocop_todo.yml +168 -15
  5. data/Gemfile +3 -2
  6. data/README.adoc +803 -1
  7. data/exe/unitsdb +7 -0
  8. data/lib/unitsdb/cli.rb +88 -0
  9. data/lib/unitsdb/commands/_modify.rb +22 -0
  10. data/lib/unitsdb/commands/base.rb +26 -0
  11. data/lib/unitsdb/commands/check_si.rb +124 -0
  12. data/lib/unitsdb/commands/get.rb +133 -0
  13. data/lib/unitsdb/commands/normalize.rb +81 -0
  14. data/lib/unitsdb/commands/release.rb +73 -0
  15. data/lib/unitsdb/commands/search.rb +219 -0
  16. data/lib/unitsdb/commands/si_formatter.rb +485 -0
  17. data/lib/unitsdb/commands/si_matcher.rb +470 -0
  18. data/lib/unitsdb/commands/si_ttl_parser.rb +100 -0
  19. data/lib/unitsdb/commands/si_updater.rb +212 -0
  20. data/lib/unitsdb/commands/ucum/check.rb +126 -0
  21. data/lib/unitsdb/commands/ucum/formatter.rb +141 -0
  22. data/lib/unitsdb/commands/ucum/matcher.rb +301 -0
  23. data/lib/unitsdb/commands/ucum/update.rb +84 -0
  24. data/lib/unitsdb/commands/ucum/updater.rb +98 -0
  25. data/lib/unitsdb/commands/ucum/xml_parser.rb +34 -0
  26. data/lib/unitsdb/commands/ucum.rb +43 -0
  27. data/lib/unitsdb/commands/validate/identifiers.rb +42 -0
  28. data/lib/unitsdb/commands/validate/references.rb +318 -0
  29. data/lib/unitsdb/commands/validate/si_references.rb +109 -0
  30. data/lib/unitsdb/commands/validate.rb +40 -0
  31. data/lib/unitsdb/database.rb +662 -0
  32. data/lib/unitsdb/dimension.rb +49 -0
  33. data/lib/unitsdb/dimension_details.rb +20 -0
  34. data/lib/unitsdb/dimension_reference.rb +8 -0
  35. data/lib/unitsdb/dimensions.rb +5 -10
  36. data/lib/unitsdb/errors.rb +13 -0
  37. data/lib/unitsdb/external_reference.rb +14 -0
  38. data/lib/unitsdb/identifier.rb +8 -0
  39. data/lib/unitsdb/localized_string.rb +17 -0
  40. data/lib/unitsdb/prefix.rb +30 -0
  41. data/lib/unitsdb/prefix_reference.rb +10 -0
  42. data/lib/unitsdb/prefixes.rb +5 -11
  43. data/lib/unitsdb/quantities.rb +5 -31
  44. data/lib/unitsdb/quantity.rb +21 -0
  45. data/lib/unitsdb/quantity_reference.rb +10 -0
  46. data/lib/unitsdb/root_unit_reference.rb +14 -0
  47. data/lib/unitsdb/scale.rb +17 -0
  48. data/lib/unitsdb/scale_properties.rb +12 -0
  49. data/lib/unitsdb/scale_reference.rb +10 -0
  50. data/lib/unitsdb/scales.rb +12 -0
  51. data/lib/unitsdb/si_derived_base.rb +19 -0
  52. data/lib/unitsdb/symbol_presentations.rb +3 -8
  53. data/lib/unitsdb/ucum.rb +198 -0
  54. data/lib/unitsdb/unit.rb +63 -0
  55. data/lib/unitsdb/unit_reference.rb +10 -0
  56. data/lib/unitsdb/unit_system.rb +15 -0
  57. data/lib/unitsdb/unit_system_reference.rb +10 -0
  58. data/lib/unitsdb/unit_systems.rb +5 -10
  59. data/lib/unitsdb/units.rb +5 -10
  60. data/lib/unitsdb/utils.rb +84 -0
  61. data/lib/unitsdb/version.rb +1 -1
  62. data/lib/unitsdb.rb +12 -2
  63. data/unitsdb.gemspec +6 -3
  64. metadata +124 -20
  65. data/lib/unitsdb/dimensions/dimension.rb +0 -59
  66. data/lib/unitsdb/dimensions/quantity.rb +0 -32
  67. data/lib/unitsdb/dimensions/symbol.rb +0 -26
  68. data/lib/unitsdb/prefixes/prefix.rb +0 -35
  69. data/lib/unitsdb/prefixes/symbol.rb +0 -17
  70. data/lib/unitsdb/quantities/quantity.rb +0 -37
  71. data/lib/unitsdb/quantities/unit_reference.rb +0 -15
  72. data/lib/unitsdb/unit_systems/unit_system.rb +0 -19
  73. data/lib/unitsdb/units/quantity_reference.rb +0 -17
  74. data/lib/unitsdb/units/root_unit.rb +0 -21
  75. data/lib/unitsdb/units/root_units.rb +0 -18
  76. data/lib/unitsdb/units/si_derived_base.rb +0 -26
  77. data/lib/unitsdb/units/symbol.rb +0 -19
  78. data/lib/unitsdb/units/system.rb +0 -17
  79. data/lib/unitsdb/units/unit.rb +0 -73
  80. data/lib/unitsdb/unitsdb.rb +0 -6
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "identifier"
4
+ require_relative "dimension_details"
5
+ require_relative "quantity"
6
+ require_relative "localized_string"
7
+ # NISTd1:
8
+ # length:
9
+ # power: 1
10
+ # symbol: L
11
+ # dim_symbols:
12
+ # - id: "dim_L"
13
+ # ascii: "L"
14
+ # html: "𝖫"
15
+ # mathml: "<mi mathvariant='sans-serif'>L</mi>"
16
+ # latex: \ensuremath{\mathsf{L}}
17
+ # unicode: "𝖫"
18
+
19
+ # NISTd9:
20
+ # -dimensionless: true
21
+ # -plane_angle:
22
+ # - dim_symbols:
23
+ # - - ascii: phi
24
+ # - html: "&#x1D785;"
25
+ # - id: dim_phi
26
+ # - latex: "\\ensuremath{\\mathsf{\\phi}}"
27
+ # - mathml: "<mi mathvariant='sans-serif'>&#x3c6;</mi>"
28
+ # - unicode: "\U0001D785"
29
+ # - power: 1
30
+ # - symbol: phi
31
+
32
+ module Unitsdb
33
+ class Dimension < Lutaml::Model::Serializable
34
+ # model Config.model_for(:dimension)
35
+
36
+ attribute :identifiers, Identifier, collection: true
37
+ attribute :dimensionless, :boolean
38
+ attribute :length, DimensionDetails
39
+ attribute :mass, DimensionDetails
40
+ attribute :time, DimensionDetails
41
+ attribute :electric_current, DimensionDetails
42
+ attribute :thermodynamic_temperature, DimensionDetails
43
+ attribute :amount_of_substance, DimensionDetails
44
+ attribute :luminous_intensity, DimensionDetails
45
+ attribute :plane_angle, DimensionDetails
46
+ attribute :short, :string
47
+ attribute :names, LocalizedString, collection: true
48
+ end
49
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # power: 1
4
+ # symbol: M
5
+ # symbols:
6
+ # - ascii: M
7
+ # html: "&#x1D5AC;"
8
+ # id: dim_M
9
+ # latex: "\\ensuremath{\\mathsf{M}}"
10
+ # mathml: "<mi mathvariant='sans-serif'>M</mi>"
11
+ # unicode: "\U0001D5AC"
12
+
13
+ require_relative "symbol_presentations"
14
+ module Unitsdb
15
+ class DimensionDetails < Lutaml::Model::Serializable
16
+ attribute :power, :integer
17
+ attribute :symbol, :string
18
+ attribute :symbols, SymbolPresentations, collection: true
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsdb
4
+ class DimensionReference < Identifier
5
+ attribute :id, :string
6
+ attribute :type, :string
7
+ end
8
+ end
@@ -1,18 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "dimensions/dimension"
3
+ require_relative "dimension"
4
4
 
5
5
  module Unitsdb
6
- class Dimensions
7
- include Lutaml::Model::Serialize
8
- model Config.model_for(:dimensions)
6
+ class Dimensions < Lutaml::Model::Serializable
7
+ # model Config.model_for(:dimensions)
9
8
 
9
+ attribute :schema_version, :string
10
+ attribute :version, :string
10
11
  attribute :dimensions, Dimension, collection: true
11
-
12
- key_value do
13
- map to: :dimensions, root_mappings: {
14
- id: :key
15
- }
16
- end
17
12
  end
18
13
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsdb
4
+ module Errors
5
+ class DatabaseError < StandardError; end
6
+ class DatabaseNotFoundError < DatabaseError; end
7
+ class DatabaseFileNotFoundError < DatabaseError; end
8
+ class DatabaseFileInvalidError < DatabaseError; end
9
+ class DatabaseLoadError < DatabaseError; end
10
+ class VersionMismatchError < DatabaseError; end
11
+ class UnsupportedVersionError < DatabaseError; end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # references:
4
+ # - uri: http://si-digital-framework.org/quantities/LENG
5
+ # type: normative
6
+ # authority: si-digital-framework
7
+
8
+ module Unitsdb
9
+ class ExternalReference < Identifier
10
+ attribute :uri, :string
11
+ attribute :type, :string, values: %w[normative informative]
12
+ attribute :authority, :string
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsdb
4
+ class Identifier < Lutaml::Model::Serializable
5
+ attribute :id, :string
6
+ attribute :type, :string
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsdb
4
+ # Represents a localized string with a language tag
5
+ class LocalizedString < Lutaml::Model::Serializable
6
+ attribute :value, :string
7
+ attribute :lang, :string
8
+
9
+ def to_s
10
+ "#{value} (#{lang})"
11
+ end
12
+
13
+ def downcase
14
+ value&.downcase
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "identifier"
4
+ require_relative "symbol_presentations"
5
+ require_relative "external_reference"
6
+ require_relative "localized_string"
7
+ # ---
8
+ # NISTp10_30:
9
+ # name: quetta
10
+ # symbol:
11
+ # ascii: Q
12
+ # html: Q
13
+ # latex: Q
14
+ # unicode: Q
15
+ # base: 10
16
+ # power: 30
17
+
18
+ module Unitsdb
19
+ class Prefix < Lutaml::Model::Serializable
20
+ # model Config.model_for(:prefix)
21
+
22
+ attribute :identifiers, Identifier, collection: true
23
+ attribute :names, LocalizedString, collection: true
24
+ attribute :short, :string
25
+ attribute :symbols, SymbolPresentations, collection: true
26
+ attribute :base, :integer
27
+ attribute :power, :integer
28
+ attribute :references, ExternalReference, collection: true
29
+ end
30
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "identifier"
4
+
5
+ module Unitsdb
6
+ class PrefixReference < Identifier
7
+ attribute :id, :string
8
+ attribute :type, :string
9
+ end
10
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "prefixes/prefix"
3
+ require_relative "prefix"
4
4
  # ---
5
5
  # NISTp10_30:
6
6
  # name: quetta
@@ -13,17 +13,11 @@ require_relative "prefixes/prefix"
13
13
  # power: 30
14
14
 
15
15
  module Unitsdb
16
- class Prefixes
17
- include Lutaml::Model::Serialize
18
-
19
- model Config.model_for(:prefixes)
16
+ class Prefixes < Lutaml::Model::Serializable
17
+ # model Config.model_for(:prefixes)
20
18
 
19
+ attribute :schema_version, :string
20
+ attribute :version, :string
21
21
  attribute :prefixes, Prefix, collection: true
22
-
23
- key_value do
24
- map to: :prefixes, root_mappings: {
25
- id: :key
26
- }
27
- end
28
22
  end
29
23
  end
@@ -1,38 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # # Quantities
4
- # NISTq156:
5
- # dimension_url: "#NISTd68"
6
- # quantity_type: derived
7
- # quantity_name:
8
- # - linear expansion coefficient
9
- # unit_reference:
10
- # - name: kelvin to the power minus one
11
- # url: "#NISTu5e-1/1"
12
-
13
- # NISTq155:
14
- # dimension_url: "#NISTd57"
15
- # quantity_type: derived
16
- # quantity_name:
17
- # - area moment of inertia
18
- # - second moment of area
19
- # unit_reference:
20
- # - name: inch to the fourth power
21
- # url: "#NISTu208"
22
-
23
- require_relative "quantities/quantity"
3
+ require_relative "quantity"
24
4
 
25
5
  module Unitsdb
26
- class Quantities
27
- include Lutaml::Model::Serialize
28
- model Config.model_for(:quantities)
29
-
6
+ class Quantities < Lutaml::Model::Serializable
7
+ # model Config.model_for(:quantities)
8
+ attribute :schema_version, :string
9
+ attribute :version, :string
30
10
  attribute :quantities, Quantity, collection: true
31
-
32
- key_value do
33
- map to: :quantities, root_mappings: {
34
- id: :key
35
- }
36
- end
37
11
  end
38
12
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "identifier"
4
+ require_relative "unit_reference"
5
+ require_relative "dimension_reference"
6
+ require_relative "external_reference"
7
+ require_relative "localized_string"
8
+
9
+ module Unitsdb
10
+ class Quantity < Lutaml::Model::Serializable
11
+ # model Config.model_for(:quantity)
12
+
13
+ attribute :identifiers, Identifier, collection: true
14
+ attribute :quantity_type, :string
15
+ attribute :names, LocalizedString, collection: true
16
+ attribute :short, :string
17
+ attribute :unit_references, UnitReference, collection: true
18
+ attribute :dimension_reference, DimensionReference
19
+ attribute :references, ExternalReference, collection: true
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsdb
4
+ class QuantityReference < Identifier
5
+ # model Config.model_for(:quantity_reference)
6
+
7
+ attribute :id, :string
8
+ attribute :type, :string
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "unit_reference"
4
+ require_relative "prefix_reference"
5
+
6
+ module Unitsdb
7
+ class RootUnitReference < Lutaml::Model::Serializable
8
+ # model Config.model_for(:root_unit)
9
+
10
+ attribute :power, :integer
11
+ attribute :unit_reference, UnitReference
12
+ attribute :prefix_reference, PrefixReference
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "identifier"
4
+ require_relative "localized_string"
5
+ require_relative "scale_properties"
6
+
7
+ module Unitsdb
8
+ class Scale < Lutaml::Model::Serializable
9
+ # model Config.model_for(:quantity)
10
+
11
+ attribute :identifiers, Identifier, collection: true
12
+ attribute :names, LocalizedString, collection: true
13
+ attribute :description, LocalizedString, collection: true
14
+ attribute :short, :string
15
+ attribute :properties, ScaleProperties
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsdb
4
+ class ScaleProperties < Lutaml::Model::Serializable
5
+ # model Config.model_for(:quantity)
6
+ attribute :continuous, :boolean
7
+ attribute :ordered, :boolean
8
+ attribute :logarithmic, :boolean
9
+ attribute :interval, :boolean
10
+ attribute :ratio, :boolean
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "identifier"
4
+
5
+ module Unitsdb
6
+ class ScaleReference < Identifier
7
+ attribute :id, :string
8
+ attribute :type, :string
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "scale"
4
+
5
+ module Unitsdb
6
+ class Scales < Lutaml::Model::Serializable
7
+ # model Config.model_for(:Scale)
8
+ attribute :schema_version, :string
9
+ attribute :version, :string
10
+ attribute :scales, Scale, collection: true
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "root_unit_reference"
4
+
5
+ # si_derived_bases:
6
+ # - power: 2
7
+ # unit_reference:
8
+ # id: NISTu1
9
+ # type: nist
10
+ # - power: -2
11
+ # unit_reference:
12
+ # id: NISTu1
13
+ # type: nist
14
+
15
+ module Unitsdb
16
+ class SiDerivedBase < RootUnitReference
17
+ # model Config.model_for(:si_derived_base)
18
+ end
19
+ end
@@ -2,18 +2,13 @@
2
2
 
3
3
  module Unitsdb
4
4
  class SymbolPresentations < Lutaml::Model::Serializable
5
- model Config.model_for(:symbol_presentations)
5
+ # model Config.model_for(:symbol_presentations)
6
6
 
7
+ attribute :id, :string
7
8
  attribute :ascii, :string
8
9
  attribute :html, :string
9
10
  attribute :latex, :string
11
+ attribute :mathml, :string
10
12
  attribute :unicode, :string
11
-
12
- key_value do
13
- map :ascii, to: :ascii
14
- map :html, to: :html
15
- map :latex, to: :latex
16
- map :unicode, to: :unicode
17
- end
18
13
  end
19
14
  end
@@ -0,0 +1,198 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "lutaml/model"
4
+
5
+ module Unitsdb
6
+ # <base-unit Code="s" CODE="S" dim="T">
7
+ # <name>second</name>
8
+ # <printSymbol>s</printSymbol>
9
+ # <property>time</property>
10
+ # </base-unit>
11
+ class UcumBaseUnit < Lutaml::Model::Serializable
12
+ attribute :code_sensitive, :string
13
+ attribute :code, :string
14
+ attribute :dimension, :string
15
+ attribute :name, :string
16
+ attribute :print_symbol, :string, raw: true
17
+ attribute :property, :string
18
+
19
+ xml do
20
+ root "base-unit"
21
+ map_attribute "Code", to: :code_sensitive
22
+ map_attribute "CODE", to: :code
23
+ map_attribute "dim", to: :dimension
24
+ map_element "name", to: :name
25
+ map_element "printSymbol", to: :print_symbol
26
+ map_element "property", to: :property
27
+ end
28
+
29
+ def identifier
30
+ "ucum:base-unit:code:#{code_sensitive}"
31
+ end
32
+ end
33
+
34
+ # <prefix Code="Y" CODE="YA">
35
+ # <name>yotta</name>
36
+ # <printSymbol>Y</printSymbol>
37
+ # <value value="1e24">1 &#215; 10<sup>24</sup>
38
+ # </value>
39
+ # </prefix>
40
+
41
+ class UcumPrefixValue < Lutaml::Model::Serializable
42
+ attribute :value, :string
43
+ attribute :content, :string
44
+
45
+ xml do
46
+ root "value"
47
+ map_attribute "value", to: :value
48
+ map_content to: :content
49
+ end
50
+ end
51
+
52
+ class UcumPrefix < Lutaml::Model::Serializable
53
+ attribute :code_sensitive, :string
54
+ attribute :code, :string
55
+ attribute :name, :string
56
+ attribute :print_symbol, :string, raw: true
57
+ attribute :value, UcumPrefixValue
58
+
59
+ xml do
60
+ root "prefix"
61
+ map_attribute "Code", to: :code_sensitive
62
+ map_attribute "CODE", to: :code
63
+ map_element "name", to: :name
64
+ map_element "printSymbol", to: :print_symbol
65
+ map_element "value", to: :value
66
+ end
67
+
68
+ def identifier
69
+ "ucum:prefix:code:#{code_sensitive}"
70
+ end
71
+ end
72
+
73
+ # <unit Code="10*" CODE="10*" isMetric="no" class="dimless">
74
+ # <name>the number ten for arbitrary powers</name>
75
+ # <printSymbol>10</printSymbol>
76
+ # <property>number</property>
77
+ # <value Unit="1" UNIT="1" value="10">10</value>
78
+ # </unit>
79
+
80
+ # <unit Code="gon" CODE="GON" isMetric="no" class="iso1000">
81
+ # <name>gon</name>
82
+ # <name>grade</name>
83
+ # <printSymbol>
84
+ # <sup>g</sup>
85
+ # </printSymbol>
86
+ # <property>plane angle</property>
87
+ # <value Unit="deg" UNIT="DEG" value="0.9">0.9</value>
88
+ # </unit>
89
+
90
+ # <unit Code="[D'ag'U]" CODE="[D'AG'U]" isMetric="no" isArbitrary="yes"
91
+ # class="chemical">
92
+ # <name>D-antigen unit</name>
93
+ # <printSymbol/>
94
+ # <property>procedure defined amount of a poliomyelitis d-antigen substance</property>
95
+ # <value Unit="1" UNIT="1" value="1">1</value>
96
+ # </unit>
97
+
98
+ # <unit Code="Cel" CODE="CEL" isMetric="yes" isSpecial="yes" class="si">
99
+ # <name>degree Celsius</name>
100
+ # <printSymbol>&#176;C</printSymbol>
101
+ # <property>temperature</property>
102
+ # <value Unit="cel(1 K)" UNIT="CEL(1 K)">
103
+ # <function name="Cel" value="1" Unit="K"/>
104
+ # </value>
105
+ # </unit>
106
+
107
+ class UcumUnitValueFunction < Lutaml::Model::Serializable
108
+ attribute :name, :string
109
+ attribute :value, :string
110
+ attribute :unit_sensitive, :string
111
+
112
+ xml do
113
+ root "function"
114
+ map_attribute "name", to: :name
115
+ map_attribute "value", to: :value
116
+ map_attribute "Unit", to: :unit_sensitive
117
+ end
118
+ end
119
+
120
+ class UcumUnitValue < Lutaml::Model::Serializable
121
+ attribute :unit_sensitive, :string
122
+ attribute :unit, :string
123
+ attribute :value, :string
124
+ attribute :function, UcumUnitValueFunction
125
+ attribute :content, :string
126
+
127
+ xml do
128
+ root "value"
129
+ map_attribute "Unit", to: :unit_sensitive
130
+ map_attribute "UNIT", to: :unit
131
+ map_attribute "value", to: :value
132
+ map_element "function", to: :function
133
+ map_content to: :content
134
+ end
135
+ end
136
+
137
+ class UcumUnit < Lutaml::Model::Serializable
138
+ attribute :code_sensitive, :string
139
+ attribute :code, :string
140
+ attribute :is_metric, :string
141
+ attribute :is_arbitrary, :string
142
+ attribute :is_special, :string
143
+ attribute :klass, :string
144
+ attribute :name, :string, collection: true
145
+ attribute :print_symbol, :string, raw: true
146
+ attribute :property, :string
147
+ attribute :value, UcumUnitValue
148
+
149
+ xml do
150
+ root "unit"
151
+ map_attribute "Code", to: :code_sensitive
152
+ map_attribute "CODE", to: :code
153
+ map_attribute "isMetric", to: :is_metric
154
+ map_attribute "isArbitrary", to: :is_arbitrary
155
+ map_attribute "isSpecial", to: :is_special
156
+ map_attribute "class", to: :klass
157
+
158
+ map_element "name", to: :name
159
+ map_element "printSymbol", to: :print_symbol
160
+ map_element "property", to: :property
161
+ map_element "value", to: :value
162
+ end
163
+
164
+ def identifier
165
+ # Use empty string if klass is not present
166
+ k = klass || ""
167
+ "ucum:unit:#{k}:code:#{code_sensitive}"
168
+ end
169
+ end
170
+
171
+ # This is the root element of the UCUM XML "ucum-essence.xml" file.
172
+ #
173
+ # <root xmlns="http://unitsofmeasure.org/ucum-essence" version="2.2" revision="N/A"
174
+ # revision-date="2024-06-17">
175
+
176
+ class UcumFile < Lutaml::Model::Serializable
177
+ attribute :revision, :string
178
+ attribute :version, :string
179
+ attribute :revision_date, :date
180
+ attribute :prefixes, UcumPrefix, collection: true
181
+ attribute :base_units, UcumBaseUnit, collection: true
182
+ attribute :units, UcumUnit, collection: true
183
+
184
+ xml do
185
+ root "root"
186
+ namespace "http://unitsofmeasure.org/ucum-essence"
187
+ map_attribute "version", to: :version
188
+ map_attribute "revision", to: :revision
189
+ map_attribute "revision-date", to: :revision_date
190
+
191
+ map_element "prefix", to: :prefixes
192
+ map_element "base-unit", to: :base_units
193
+ map_element "unit", to: :units
194
+ end
195
+
196
+ # No adapter registration needed
197
+ end
198
+ end