unitsdb 2.2.1 → 2.2.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/Gemfile +1 -1
- data/lib/unitsdb/config.rb +114 -2
- data/lib/unitsdb/database.rb +90 -91
- data/lib/unitsdb/dimension.rb +2 -0
- data/lib/unitsdb/dimension_details.rb +2 -0
- data/lib/unitsdb/dimension_reference.rb +2 -0
- data/lib/unitsdb/dimensions.rb +2 -0
- data/lib/unitsdb/external_reference.rb +2 -0
- data/lib/unitsdb/identifier.rb +2 -0
- data/lib/unitsdb/localized_string.rb +2 -0
- data/lib/unitsdb/prefix.rb +2 -0
- data/lib/unitsdb/prefix_reference.rb +2 -0
- data/lib/unitsdb/prefixes.rb +2 -0
- data/lib/unitsdb/quantities.rb +2 -0
- data/lib/unitsdb/quantity.rb +2 -0
- data/lib/unitsdb/quantity_reference.rb +2 -0
- data/lib/unitsdb/qudt.rb +5 -0
- data/lib/unitsdb/root_unit_reference.rb +2 -0
- data/lib/unitsdb/scale.rb +2 -0
- data/lib/unitsdb/scale_properties.rb +2 -0
- data/lib/unitsdb/scale_reference.rb +2 -0
- data/lib/unitsdb/scales.rb +2 -0
- data/lib/unitsdb/si_derived_base.rb +2 -0
- data/lib/unitsdb/symbol_presentations.rb +2 -0
- data/lib/unitsdb/ucum.rb +7 -0
- data/lib/unitsdb/unit.rb +2 -0
- data/lib/unitsdb/unit_reference.rb +2 -0
- data/lib/unitsdb/unit_system.rb +2 -0
- data/lib/unitsdb/unit_system_reference.rb +2 -0
- data/lib/unitsdb/unit_systems.rb +2 -0
- data/lib/unitsdb/units.rb +2 -0
- data/lib/unitsdb/version.rb +1 -1
- data/lib/unitsdb.rb +45 -45
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e2982ead6dc990098c687109bd98560cd35945c6272e01a88bcd4f1270ffdffa
|
|
4
|
+
data.tar.gz: f89db123f11036b7963fd5fc60a1e37476cd7dac43664be26c95776089479844
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 811a621748d4936a1668e7f6969e5090f4da626b7ca0122bbce24ea1d3b217a533d2ea0e5759a812c22faa4d097941538e9273db4c2f84beb908ee301c0ef51a
|
|
7
|
+
data.tar.gz: 23456a3351a981a001f57476bba3815b95c93ce65008189bf1334ae87cf6c0aa57201f897301c8579e0cc9866af10dc2989eb9a58af1aad2c7e63c15d6f05e42
|
data/Gemfile
CHANGED
|
@@ -6,7 +6,7 @@ source "https://rubygems.org"
|
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
8
|
gem "canon"
|
|
9
|
-
gem "lutaml-model", github: "lutaml/lutaml-model", branch: "
|
|
9
|
+
gem "lutaml-model", github: "lutaml/lutaml-model", branch: "fix/global-context-register-lookup-fallback"
|
|
10
10
|
gem "nokogiri"
|
|
11
11
|
gem "rake"
|
|
12
12
|
gem "rspec"
|
data/lib/unitsdb/config.rb
CHANGED
|
@@ -2,17 +2,129 @@
|
|
|
2
2
|
|
|
3
3
|
module Unitsdb
|
|
4
4
|
class Config
|
|
5
|
+
CONTEXT_ID = :unitsdb_v2
|
|
6
|
+
|
|
5
7
|
class << self
|
|
8
|
+
def context_id
|
|
9
|
+
@context_id ||= CONTEXT_ID
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def register_model(klass, id:)
|
|
13
|
+
registered_models[id.to_sym] = klass
|
|
14
|
+
klass
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def registered_models
|
|
18
|
+
@registered_models ||= {}
|
|
19
|
+
end
|
|
20
|
+
|
|
6
21
|
def models
|
|
7
22
|
@models ||= {}
|
|
8
23
|
end
|
|
9
24
|
|
|
10
25
|
def models=(user_models)
|
|
11
|
-
|
|
26
|
+
normalized_models = user_models.each_with_object({}) do |(id, klass), result|
|
|
27
|
+
model_id = id.to_sym
|
|
28
|
+
result[model_id] = register_model(klass, id: model_id)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
models.merge!(normalized_models)
|
|
12
32
|
end
|
|
13
33
|
|
|
14
34
|
def model_for(model_name)
|
|
15
|
-
|
|
35
|
+
model_id = model_name.to_sym
|
|
36
|
+
models[model_id] || registered_models[model_id]
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def register(id = context_id)
|
|
40
|
+
explicit_registers[id.to_sym]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def populate_register(id: context_id, fallback_to: [:default], substitutions: [])
|
|
44
|
+
register_id = id.to_sym
|
|
45
|
+
context(register_id)
|
|
46
|
+
|
|
47
|
+
model_register = Lutaml::Model::Register.new(register_id, fallback: fallback_to)
|
|
48
|
+
resolve_substitutions(
|
|
49
|
+
substitutions,
|
|
50
|
+
registry: build_registry,
|
|
51
|
+
fallback_to: fallback_to,
|
|
52
|
+
id: "#{register_id}_register",
|
|
53
|
+
).each do |substitution|
|
|
54
|
+
model_register.register_global_type_substitution(**substitution)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
explicit_registers[register_id] = Lutaml::Model::GlobalRegister.register(model_register)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def find_context(id)
|
|
61
|
+
Lutaml::Model::GlobalContext.context(id.to_sym)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def resolve_type(type_name, context: context_id)
|
|
65
|
+
Lutaml::Model::GlobalContext.resolve_type(type_name, context.to_sym)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def context(id = context_id, force_populate: false)
|
|
69
|
+
existing = find_context(id)
|
|
70
|
+
return existing if existing && !force_populate && populated?(id)
|
|
71
|
+
|
|
72
|
+
populate_context(id: id)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def populate_context(id: context_id, fallback_to: [:default], substitutions: [])
|
|
76
|
+
Lutaml::Model::GlobalContext.unregister_context(id) if find_context(id)
|
|
77
|
+
|
|
78
|
+
opts = { registry: build_registry, fallback_to: fallback_to, id: id }
|
|
79
|
+
context = Lutaml::Model::GlobalContext.create_context(
|
|
80
|
+
substitutions: resolve_substitutions(substitutions, **opts),
|
|
81
|
+
**opts,
|
|
82
|
+
)
|
|
83
|
+
mark_populated!(id)
|
|
84
|
+
context
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def resolve_substitutions(substitutions, registry:, fallback_to:, id:)
|
|
88
|
+
resolution_context = Lutaml::Model::TypeContext.derived(
|
|
89
|
+
id: "#{id}_substitution_resolution",
|
|
90
|
+
registry: registry,
|
|
91
|
+
fallback_to: fallback_to,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
Array(substitutions).map do |substitution|
|
|
95
|
+
from_key = substitution[:from_type] || substitution[:from]
|
|
96
|
+
to_key = substitution[:to_type] || substitution[:to]
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
from_type: resolve_substitution_type(from_key, resolution_context),
|
|
100
|
+
to_type: resolve_substitution_type(to_key, resolution_context),
|
|
101
|
+
}
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def resolve_substitution_type(value, resolution_context)
|
|
106
|
+
return value if value.is_a?(Class)
|
|
107
|
+
|
|
108
|
+
Lutaml::Model::TypeResolver.resolve(value, resolution_context)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def build_registry
|
|
112
|
+
registry = Lutaml::Model::TypeRegistry.new
|
|
113
|
+
registered_models.each { |model_id, klass| registry.register(model_id, klass) }
|
|
114
|
+
registry
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def populated?(context_id)
|
|
118
|
+
@populated_for&.[](context_id.to_sym)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def mark_populated!(context_id)
|
|
122
|
+
@populated_for ||= {}
|
|
123
|
+
@populated_for[context_id.to_sym] = true
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def explicit_registers
|
|
127
|
+
@explicit_registers ||= {}
|
|
16
128
|
end
|
|
17
129
|
end
|
|
18
130
|
end
|
data/lib/unitsdb/database.rb
CHANGED
|
@@ -4,6 +4,15 @@ module Unitsdb
|
|
|
4
4
|
class Database < Lutaml::Model::Serializable
|
|
5
5
|
# model Config.model_for(:units)
|
|
6
6
|
|
|
7
|
+
DATABASE_FILES = {
|
|
8
|
+
"prefixes" => "prefixes.yaml",
|
|
9
|
+
"dimensions" => "dimensions.yaml",
|
|
10
|
+
"units" => "units.yaml",
|
|
11
|
+
"quantities" => "quantities.yaml",
|
|
12
|
+
"unit_systems" => "unit_systems.yaml",
|
|
13
|
+
}.freeze
|
|
14
|
+
SUPPORTED_SCHEMA_VERSION = "2.0.0"
|
|
15
|
+
|
|
7
16
|
attribute :schema_version, :string
|
|
8
17
|
attribute :version, :string
|
|
9
18
|
attribute :units, Unit, collection: true
|
|
@@ -290,25 +299,21 @@ module Unitsdb
|
|
|
290
299
|
invalid_refs
|
|
291
300
|
end
|
|
292
301
|
|
|
293
|
-
def self.from_db(dir_path)
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
302
|
+
def self.from_db(dir_path, context: Unitsdb::Config.context_id)
|
|
303
|
+
context_id = context.to_sym
|
|
304
|
+
if context_id == Unitsdb::Config.context_id &&
|
|
305
|
+
Unitsdb::Config.find_context(context_id).nil?
|
|
306
|
+
Unitsdb::Config.context(context_id)
|
|
307
|
+
end
|
|
297
308
|
|
|
298
|
-
|
|
309
|
+
db_path = File.expand_path(dir_path.to_s)
|
|
299
310
|
unless Dir.exist?(db_path)
|
|
300
311
|
raise Errors::DatabaseNotFoundError,
|
|
301
312
|
"Database directory not found: #{db_path}"
|
|
302
313
|
end
|
|
303
314
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
quantities.yaml unit_systems.yaml]
|
|
307
|
-
yaml_files = required_files.map { |file| File.join(dir_path, file) }
|
|
308
|
-
|
|
309
|
-
# Check if all required files exist
|
|
310
|
-
missing_files = required_files.reject do |file|
|
|
311
|
-
File.exist?(File.join(dir_path, file))
|
|
315
|
+
missing_files = DATABASE_FILES.values.reject do |filename|
|
|
316
|
+
File.exist?(File.join(db_path, filename))
|
|
312
317
|
end
|
|
313
318
|
|
|
314
319
|
if missing_files.any?
|
|
@@ -316,99 +321,92 @@ module Unitsdb
|
|
|
316
321
|
"Missing required database files: #{missing_files.join(', ')}"
|
|
317
322
|
end
|
|
318
323
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
puts " - #{prefixes_yaml}"
|
|
330
|
-
puts " - #{dimensions_yaml}"
|
|
331
|
-
puts " - #{units_yaml}"
|
|
332
|
-
puts " - #{quantities_yaml}"
|
|
333
|
-
puts " - #{unit_systems_yaml}"
|
|
324
|
+
documents = load_database_documents(db_path)
|
|
325
|
+
schema_version = validate_schema_versions!(documents)
|
|
326
|
+
combined_hash = build_database_hash(documents, schema_version)
|
|
327
|
+
|
|
328
|
+
Lutaml::Model::GlobalContext.with_context(context_id) do
|
|
329
|
+
if Unitsdb::Config.register(context_id)
|
|
330
|
+
from_hash(combined_hash, register: context_id)
|
|
331
|
+
else
|
|
332
|
+
from_hash(combined_hash)
|
|
333
|
+
end
|
|
334
334
|
end
|
|
335
|
+
end
|
|
335
336
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
337
|
+
def self.load_database_documents(db_path)
|
|
338
|
+
puts "[UnitsDB] Loading YAML files from directory: #{db_path}" if ENV["UNITSDB_DEBUG"]
|
|
339
|
+
DATABASE_FILES.transform_values do |filename|
|
|
340
|
+
puts " - #{File.join(db_path, filename)}" if ENV["UNITSDB_DEBUG"]
|
|
341
|
+
load_database_yaml(File.join(db_path, filename), filename)
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
def self.load_database_yaml(path, filename)
|
|
346
|
+
document = YAML.safe_load_file(path)
|
|
347
|
+
|
|
348
|
+
unless document.is_a?(Hash)
|
|
347
349
|
raise Errors::DatabaseFileInvalidError,
|
|
348
|
-
"Invalid YAML in
|
|
349
|
-
rescue StandardError => e
|
|
350
|
-
raise Errors::DatabaseLoadError, "Error loading database: #{e.message}"
|
|
350
|
+
"Invalid YAML structure in #{filename}: expected a mapping"
|
|
351
351
|
end
|
|
352
352
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
353
|
+
document
|
|
354
|
+
rescue Errno::ENOENT => e
|
|
355
|
+
raise Errors::DatabaseFileNotFoundError,
|
|
356
|
+
"Failed to read database file: #{e.message}"
|
|
357
|
+
rescue Psych::SyntaxError => e
|
|
358
|
+
raise Errors::DatabaseFileInvalidError,
|
|
359
|
+
"Invalid YAML in database file: #{e.message}"
|
|
360
|
+
rescue Errors::DatabaseError
|
|
361
|
+
raise
|
|
362
|
+
rescue StandardError => e
|
|
363
|
+
raise Errors::DatabaseLoadError,
|
|
364
|
+
"Error loading database file #{filename}: #{e.message}"
|
|
365
|
+
end
|
|
366
|
+
private_class_method :load_database_documents, :load_database_yaml
|
|
360
367
|
|
|
361
|
-
|
|
368
|
+
def self.validate_schema_versions!(documents)
|
|
369
|
+
versions = DATABASE_FILES.each_with_object({}) do |(collection_key, filename), result|
|
|
370
|
+
document = documents.fetch(collection_key)
|
|
371
|
+
result[filename] = document.fetch("schema_version")
|
|
372
|
+
rescue KeyError
|
|
362
373
|
raise Errors::DatabaseFileInvalidError,
|
|
363
|
-
"Missing schema_version in
|
|
374
|
+
"Missing schema_version in #{filename}"
|
|
364
375
|
end
|
|
365
376
|
|
|
366
|
-
|
|
367
|
-
prefixes_version = prefixes_hash["schema_version"]
|
|
368
|
-
dimensions_version = dimensions_hash["schema_version"]
|
|
369
|
-
units_version = units_hash["schema_version"]
|
|
370
|
-
quantities_version = quantities_hash["schema_version"]
|
|
371
|
-
unit_systems_version = unit_systems_hash["schema_version"]
|
|
372
|
-
|
|
373
|
-
# Check if all versions match
|
|
374
|
-
versions = [
|
|
375
|
-
prefixes_version,
|
|
376
|
-
dimensions_version,
|
|
377
|
-
units_version,
|
|
378
|
-
quantities_version,
|
|
379
|
-
unit_systems_version,
|
|
380
|
-
]
|
|
381
|
-
|
|
382
|
-
unless versions.uniq.size == 1
|
|
383
|
-
version_info = {
|
|
384
|
-
"prefixes.yaml" => prefixes_version,
|
|
385
|
-
"dimensions.yaml" => dimensions_version,
|
|
386
|
-
"units.yaml" => units_version,
|
|
387
|
-
"quantities.yaml" => quantities_version,
|
|
388
|
-
"unit_systems.yaml" => unit_systems_version,
|
|
389
|
-
}
|
|
377
|
+
unless versions.values.uniq.size == 1
|
|
390
378
|
raise Errors::VersionMismatchError,
|
|
391
|
-
"Version mismatch in database files: #{
|
|
379
|
+
"Version mismatch in database files: #{versions.inspect}"
|
|
392
380
|
end
|
|
393
381
|
|
|
394
|
-
|
|
395
|
-
version
|
|
396
|
-
unless version == "2.0.0"
|
|
382
|
+
version = versions.values.first
|
|
383
|
+
unless version == SUPPORTED_SCHEMA_VERSION
|
|
397
384
|
raise Errors::UnsupportedVersionError,
|
|
398
|
-
"Unsupported database version: #{version}. Only version
|
|
385
|
+
"Unsupported database version: #{version}. Only version #{SUPPORTED_SCHEMA_VERSION} is supported."
|
|
399
386
|
end
|
|
400
387
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
"
|
|
407
|
-
|
|
408
|
-
|
|
388
|
+
version
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
def self.build_database_hash(documents, schema_version)
|
|
392
|
+
{
|
|
393
|
+
"schema_version" => schema_version,
|
|
394
|
+
}.merge(
|
|
395
|
+
DATABASE_FILES.keys.to_h do |collection_key|
|
|
396
|
+
document = documents.fetch(collection_key)
|
|
397
|
+
[collection_key, fetch_collection!(document, collection_key)]
|
|
398
|
+
end,
|
|
399
|
+
)
|
|
400
|
+
end
|
|
409
401
|
|
|
410
|
-
|
|
402
|
+
def self.fetch_collection!(document, collection_key)
|
|
403
|
+
document.fetch(collection_key)
|
|
404
|
+
rescue KeyError
|
|
405
|
+
raise Errors::DatabaseFileInvalidError,
|
|
406
|
+
"Missing #{collection_key} collection in #{DATABASE_FILES.fetch(collection_key)}"
|
|
411
407
|
end
|
|
408
|
+
private_class_method :validate_schema_versions!, :build_database_hash,
|
|
409
|
+
:fetch_collection!
|
|
412
410
|
|
|
413
411
|
private
|
|
414
412
|
|
|
@@ -616,8 +614,7 @@ module Unitsdb
|
|
|
616
614
|
end
|
|
617
615
|
end
|
|
618
616
|
|
|
619
|
-
def validate_reference(ref_id, ref_type, ref_path, registry, invalid_refs,
|
|
620
|
-
file_type)
|
|
617
|
+
def validate_reference(ref_id, ref_type, ref_path, registry, invalid_refs, file_type)
|
|
621
618
|
# Handle references that are objects with id and type (could be a hash or an object)
|
|
622
619
|
if ref_id.respond_to?(:id) && ref_id.respond_to?(:type)
|
|
623
620
|
id = ref_id.id
|
|
@@ -697,4 +694,6 @@ file_type)
|
|
|
697
694
|
end
|
|
698
695
|
end
|
|
699
696
|
end
|
|
697
|
+
|
|
698
|
+
Config.register_model(Database, id: :database)
|
|
700
699
|
end
|
data/lib/unitsdb/dimension.rb
CHANGED
data/lib/unitsdb/dimensions.rb
CHANGED
data/lib/unitsdb/identifier.rb
CHANGED
data/lib/unitsdb/prefix.rb
CHANGED
data/lib/unitsdb/prefixes.rb
CHANGED
data/lib/unitsdb/quantities.rb
CHANGED
data/lib/unitsdb/quantity.rb
CHANGED
data/lib/unitsdb/qudt.rb
CHANGED
|
@@ -18,6 +18,7 @@ module Unitsdb
|
|
|
18
18
|
"qudt:unit:#{uri}"
|
|
19
19
|
end
|
|
20
20
|
end
|
|
21
|
+
Config.register_model(QudtUnit, id: :qudt_unit)
|
|
21
22
|
|
|
22
23
|
# QUDT QuantityKind from quantitykinds vocabulary
|
|
23
24
|
# Example: http://qudt.org/vocab/quantitykind/Length
|
|
@@ -33,6 +34,7 @@ module Unitsdb
|
|
|
33
34
|
"qudt:quantitykind:#{uri}"
|
|
34
35
|
end
|
|
35
36
|
end
|
|
37
|
+
Config.register_model(QudtQuantityKind, id: :qudt_quantity_kind)
|
|
36
38
|
|
|
37
39
|
# QUDT DimensionVector from dimensionvectors vocabulary
|
|
38
40
|
# Example: http://qudt.org/vocab/dimensionvector/A0E0L1I0M0H0T0D0
|
|
@@ -52,6 +54,7 @@ module Unitsdb
|
|
|
52
54
|
"qudt:dimensionvector:#{uri}"
|
|
53
55
|
end
|
|
54
56
|
end
|
|
57
|
+
Config.register_model(QudtDimensionVector, id: :qudt_dimension_vector)
|
|
55
58
|
|
|
56
59
|
# QUDT SystemOfUnits from sou vocabulary
|
|
57
60
|
# Example: http://qudt.org/vocab/sou/SI
|
|
@@ -65,6 +68,7 @@ module Unitsdb
|
|
|
65
68
|
"qudt:sou:#{uri}"
|
|
66
69
|
end
|
|
67
70
|
end
|
|
71
|
+
Config.register_model(QudtSystemOfUnits, id: :qudt_system_of_units)
|
|
68
72
|
|
|
69
73
|
# QUDT Prefix from prefixes vocabulary
|
|
70
74
|
# Example: http://qudt.org/vocab/prefix/Kilo
|
|
@@ -83,6 +87,7 @@ module Unitsdb
|
|
|
83
87
|
"qudt:prefix:#{uri}"
|
|
84
88
|
end
|
|
85
89
|
end
|
|
90
|
+
Config.register_model(QudtPrefix, id: :qudt_prefix)
|
|
86
91
|
|
|
87
92
|
# Container for all QUDT vocabularies
|
|
88
93
|
class QudtVocabularies
|
data/lib/unitsdb/scale.rb
CHANGED
data/lib/unitsdb/scales.rb
CHANGED
data/lib/unitsdb/ucum.rb
CHANGED
|
@@ -28,6 +28,7 @@ module Unitsdb
|
|
|
28
28
|
"ucum:base-unit:code:#{code_sensitive}"
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
|
+
Config.register_model(UcumBaseUnit, id: :ucum_base_unit)
|
|
31
32
|
|
|
32
33
|
# <prefix Code="Y" CODE="YA">
|
|
33
34
|
# <name>yotta</name>
|
|
@@ -46,6 +47,7 @@ module Unitsdb
|
|
|
46
47
|
map_content to: :content
|
|
47
48
|
end
|
|
48
49
|
end
|
|
50
|
+
Config.register_model(UcumPrefixValue, id: :ucum_prefix_value)
|
|
49
51
|
|
|
50
52
|
class UcumPrefix < Lutaml::Model::Serializable
|
|
51
53
|
attribute :code_sensitive, :string
|
|
@@ -67,6 +69,7 @@ module Unitsdb
|
|
|
67
69
|
"ucum:prefix:code:#{code_sensitive}"
|
|
68
70
|
end
|
|
69
71
|
end
|
|
72
|
+
Config.register_model(UcumPrefix, id: :ucum_prefix)
|
|
70
73
|
|
|
71
74
|
# <unit Code="10*" CODE="10*" isMetric="no" class="dimless">
|
|
72
75
|
# <name>the number ten for arbitrary powers</name>
|
|
@@ -114,6 +117,7 @@ module Unitsdb
|
|
|
114
117
|
map_attribute "Unit", to: :unit_sensitive
|
|
115
118
|
end
|
|
116
119
|
end
|
|
120
|
+
Config.register_model(UcumUnitValueFunction, id: :ucum_unit_value_function)
|
|
117
121
|
|
|
118
122
|
class UcumUnitValue < Lutaml::Model::Serializable
|
|
119
123
|
attribute :unit_sensitive, :string
|
|
@@ -131,6 +135,7 @@ module Unitsdb
|
|
|
131
135
|
map_content to: :content
|
|
132
136
|
end
|
|
133
137
|
end
|
|
138
|
+
Config.register_model(UcumUnitValue, id: :ucum_unit_value)
|
|
134
139
|
|
|
135
140
|
class UcumUnit < Lutaml::Model::Serializable
|
|
136
141
|
attribute :code_sensitive, :string
|
|
@@ -165,6 +170,7 @@ module Unitsdb
|
|
|
165
170
|
"ucum:unit:#{k}:code:#{code_sensitive}"
|
|
166
171
|
end
|
|
167
172
|
end
|
|
173
|
+
Config.register_model(UcumUnit, id: :ucum_unit)
|
|
168
174
|
|
|
169
175
|
class UcumNamespace < Lutaml::Xml::Namespace
|
|
170
176
|
uri "http://unitsofmeasure.org/ucum-essence"
|
|
@@ -199,4 +205,5 @@ module Unitsdb
|
|
|
199
205
|
|
|
200
206
|
# No adapter registration needed
|
|
201
207
|
end
|
|
208
|
+
Config.register_model(UcumFile, id: :ucum_file)
|
|
202
209
|
end
|
data/lib/unitsdb/unit.rb
CHANGED
data/lib/unitsdb/unit_system.rb
CHANGED
data/lib/unitsdb/unit_systems.rb
CHANGED
data/lib/unitsdb/units.rb
CHANGED
data/lib/unitsdb/version.rb
CHANGED
data/lib/unitsdb.rb
CHANGED
|
@@ -1,52 +1,45 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "lutaml/model"
|
|
4
|
+
require "unitsdb/config"
|
|
5
|
+
require "unitsdb/identifier"
|
|
6
|
+
require "unitsdb/localized_string"
|
|
7
|
+
require "unitsdb/symbol_presentations"
|
|
8
|
+
require "unitsdb/scale_properties"
|
|
9
|
+
require "unitsdb/unit_reference"
|
|
10
|
+
require "unitsdb/prefix_reference"
|
|
11
|
+
require "unitsdb/quantity_reference"
|
|
12
|
+
require "unitsdb/dimension_reference"
|
|
13
|
+
require "unitsdb/unit_system_reference"
|
|
14
|
+
require "unitsdb/scale_reference"
|
|
15
|
+
require "unitsdb/external_reference"
|
|
16
|
+
require "unitsdb/root_unit_reference"
|
|
17
|
+
require "unitsdb/si_derived_base"
|
|
18
|
+
require "unitsdb/dimension_details"
|
|
19
|
+
require "unitsdb/dimension"
|
|
20
|
+
require "unitsdb/prefix"
|
|
21
|
+
require "unitsdb/unit_system"
|
|
22
|
+
require "unitsdb/quantity"
|
|
23
|
+
require "unitsdb/scale"
|
|
24
|
+
require "unitsdb/unit"
|
|
25
|
+
require "unitsdb/dimensions"
|
|
26
|
+
require "unitsdb/prefixes"
|
|
27
|
+
require "unitsdb/quantities"
|
|
28
|
+
require "unitsdb/scales"
|
|
29
|
+
require "unitsdb/unit_systems"
|
|
30
|
+
require "unitsdb/units"
|
|
31
|
+
require "unitsdb/database"
|
|
32
|
+
require "unitsdb/qudt"
|
|
33
|
+
require "unitsdb/ucum"
|
|
4
34
|
|
|
5
35
|
module Unitsdb
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
autoload :DimensionReference, "unitsdb/dimension_reference"
|
|
13
|
-
autoload :Dimensions, "unitsdb/dimensions"
|
|
36
|
+
# Core models are eagerly loaded so type registrations are complete before
|
|
37
|
+
# any context or database loading happens.
|
|
38
|
+
unless RUBY_ENGINE == "opal"
|
|
39
|
+
autoload :Cli, "unitsdb/cli"
|
|
40
|
+
autoload :Commands, "unitsdb/commands"
|
|
41
|
+
end
|
|
14
42
|
autoload :Errors, "unitsdb/errors"
|
|
15
|
-
autoload :ExternalReference, "unitsdb/external_reference"
|
|
16
|
-
autoload :Identifier, "unitsdb/identifier"
|
|
17
|
-
autoload :LocalizedString, "unitsdb/localized_string"
|
|
18
|
-
autoload :Prefix, "unitsdb/prefix"
|
|
19
|
-
autoload :PrefixReference, "unitsdb/prefix_reference"
|
|
20
|
-
autoload :Prefixes, "unitsdb/prefixes"
|
|
21
|
-
autoload :Quantities, "unitsdb/quantities"
|
|
22
|
-
autoload :Quantity, "unitsdb/quantity"
|
|
23
|
-
autoload :QuantityReference, "unitsdb/quantity_reference"
|
|
24
|
-
autoload :QudtUnit, "unitsdb/qudt"
|
|
25
|
-
autoload :QudtQuantityKind, "unitsdb/qudt"
|
|
26
|
-
autoload :QudtDimensionVector, "unitsdb/qudt"
|
|
27
|
-
autoload :QudtSystemOfUnits, "unitsdb/qudt"
|
|
28
|
-
autoload :QudtPrefix, "unitsdb/qudt"
|
|
29
|
-
autoload :QudtVocabularies, "unitsdb/qudt"
|
|
30
|
-
autoload :RootUnitReference, "unitsdb/root_unit_reference"
|
|
31
|
-
autoload :Scale, "unitsdb/scale"
|
|
32
|
-
autoload :ScaleProperties, "unitsdb/scale_properties"
|
|
33
|
-
autoload :ScaleReference, "unitsdb/scale_reference"
|
|
34
|
-
autoload :Scales, "unitsdb/scales"
|
|
35
|
-
autoload :SiDerivedBase, "unitsdb/si_derived_base"
|
|
36
|
-
autoload :SymbolPresentations, "unitsdb/symbol_presentations"
|
|
37
|
-
autoload :UcumBaseUnit, "unitsdb/ucum"
|
|
38
|
-
autoload :UcumPrefixValue, "unitsdb/ucum"
|
|
39
|
-
autoload :UcumPrefix, "unitsdb/ucum"
|
|
40
|
-
autoload :UcumUnitValueFunction, "unitsdb/ucum"
|
|
41
|
-
autoload :UcumUnitValue, "unitsdb/ucum"
|
|
42
|
-
autoload :UcumUnit, "unitsdb/ucum"
|
|
43
|
-
autoload :UcumFile, "unitsdb/ucum"
|
|
44
|
-
autoload :Unit, "unitsdb/unit"
|
|
45
|
-
autoload :UnitReference, "unitsdb/unit_reference"
|
|
46
|
-
autoload :UnitSystem, "unitsdb/unit_system"
|
|
47
|
-
autoload :UnitSystemReference, "unitsdb/unit_system_reference"
|
|
48
|
-
autoload :UnitSystems, "unitsdb/unit_systems"
|
|
49
|
-
autoload :Units, "unitsdb/units"
|
|
50
43
|
autoload :Utils, "unitsdb/utils"
|
|
51
44
|
|
|
52
45
|
class << self
|
|
@@ -56,12 +49,19 @@ module Unitsdb
|
|
|
56
49
|
end
|
|
57
50
|
|
|
58
51
|
# Returns a pre-loaded Database instance from the bundled data
|
|
59
|
-
def database
|
|
60
|
-
|
|
52
|
+
def database(context: Config.context_id)
|
|
53
|
+
context_id = context.to_sym
|
|
54
|
+
Config.context(context_id) if context_id == Config.context_id && Config.find_context(context_id).nil?
|
|
55
|
+
klass = Config.resolve_type(:database, context: context_id)
|
|
56
|
+
databases[context_id] ||= klass.from_db(data_dir, context: context_id)
|
|
61
57
|
end
|
|
62
58
|
|
|
63
59
|
private
|
|
64
60
|
|
|
61
|
+
def databases
|
|
62
|
+
@databases ||= {}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
65
|
def gem_dir
|
|
66
66
|
@gem_dir ||= File.dirname(__dir__)
|
|
67
67
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unitsdb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.2.
|
|
4
|
+
version: 2.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fuzzy_match
|