unitsml 0.6.2 → 0.6.4
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_todo.yml +23 -9
- data/Gemfile +5 -3
- data/docs/README.adoc +16 -2
- data/lib/unitsml/configuration.rb +47 -0
- data/lib/unitsml/dimension.rb +10 -4
- data/lib/unitsml/errors/opal_payload_not_bundled_error.rb +11 -0
- data/lib/unitsml/errors.rb +2 -0
- data/lib/unitsml/extender.rb +3 -1
- data/lib/unitsml/fenced.rb +6 -2
- data/lib/unitsml/formula.rb +14 -14
- data/lib/unitsml/mathml_helper.rb +60 -0
- data/lib/unitsml/number.rb +5 -3
- data/lib/unitsml/prefix.rb +3 -1
- data/lib/unitsml/unit.rb +10 -3
- data/lib/unitsml/unitsdb/database.rb +22 -0
- data/lib/unitsml/unitsdb/dimension.rb +23 -20
- data/lib/unitsml/unitsdb/{dimension_quantity.rb → dimension_details.rb} +3 -1
- data/lib/unitsml/unitsdb/dimensions.rb +2 -0
- data/lib/unitsml/unitsdb/prefix_reference.rb +3 -1
- data/lib/unitsml/unitsdb/prefixes.rb +2 -0
- data/lib/unitsml/unitsdb/quantities.rb +2 -0
- data/lib/unitsml/unitsdb/unit.rb +2 -8
- data/lib/unitsml/unitsdb/units.rb +2 -4
- data/lib/unitsml/unitsdb.rb +82 -14
- data/lib/unitsml/utility.rb +160 -35
- data/lib/unitsml/version.rb +1 -1
- data/lib/unitsml.rb +3 -44
- data/unitsml.gemspec +3 -3
- metadata +13 -11
- data/lib/unitsml/unitsdb/si_derived_base.rb +0 -14
|
@@ -3,10 +3,6 @@
|
|
|
3
3
|
module Unitsml
|
|
4
4
|
module Unitsdb
|
|
5
5
|
class Units < ::Unitsdb::Units
|
|
6
|
-
def units=(value)
|
|
7
|
-
super(value.map { |u| Unit.new(u.to_hash) })
|
|
8
|
-
end
|
|
9
|
-
|
|
10
6
|
def find_by_id(u_id)
|
|
11
7
|
find(u_id, :id, :identifiers)
|
|
12
8
|
end
|
|
@@ -45,5 +41,7 @@ module Unitsml
|
|
|
45
41
|
end
|
|
46
42
|
end
|
|
47
43
|
end
|
|
44
|
+
|
|
45
|
+
Configuration.register_model(Units, id: :units)
|
|
48
46
|
end
|
|
49
47
|
end
|
data/lib/unitsml/unitsdb.rb
CHANGED
|
@@ -1,32 +1,53 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "unitsdb"
|
|
4
|
+
|
|
5
|
+
require_relative "unitsdb/database"
|
|
6
|
+
require_relative "unitsdb/dimension_details"
|
|
7
|
+
require_relative "unitsdb/prefix_reference"
|
|
8
|
+
require_relative "unitsdb/dimension"
|
|
9
|
+
require_relative "unitsdb/dimensions"
|
|
10
|
+
require_relative "unitsdb/unit"
|
|
11
|
+
require_relative "unitsdb/units"
|
|
12
|
+
require_relative "unitsdb/prefixes"
|
|
13
|
+
require_relative "unitsdb/quantities"
|
|
3
14
|
module Unitsml
|
|
4
15
|
module Unitsdb
|
|
5
|
-
autoload :Unit, "#{__dir__}/unitsdb/unit"
|
|
6
|
-
autoload :Units, "#{__dir__}/unitsdb/units"
|
|
7
|
-
autoload :Prefixes, "#{__dir__}/unitsdb/prefixes"
|
|
8
|
-
autoload :Dimension, "#{__dir__}/unitsdb/dimension"
|
|
9
|
-
autoload :Dimensions, "#{__dir__}/unitsdb/dimensions"
|
|
10
|
-
autoload :Quantities, "#{__dir__}/unitsdb/quantities"
|
|
11
|
-
autoload :PrefixReference, "#{__dir__}/unitsdb/prefix_reference"
|
|
12
|
-
autoload :DimensionQuantity, "#{__dir__}/unitsdb/dimension_quantity"
|
|
13
|
-
autoload :SiDerivedBase, "#{__dir__}/unitsdb/si_derived_base"
|
|
14
|
-
|
|
15
16
|
class << self
|
|
17
|
+
REQUIRED_DATABASE_FILES = %w[
|
|
18
|
+
prefixes.yaml
|
|
19
|
+
dimensions.yaml
|
|
20
|
+
units.yaml
|
|
21
|
+
quantities.yaml
|
|
22
|
+
unit_systems.yaml
|
|
23
|
+
].freeze
|
|
24
|
+
|
|
16
25
|
def units
|
|
17
|
-
Units.new(
|
|
26
|
+
@units ||= Units.new(
|
|
27
|
+
units: database.units,
|
|
28
|
+
lutaml_register: Configuration.context.id,
|
|
29
|
+
)
|
|
18
30
|
end
|
|
19
31
|
|
|
20
32
|
def prefixes
|
|
21
|
-
Prefixes.new(
|
|
33
|
+
@prefixes ||= Prefixes.new(
|
|
34
|
+
prefixes: database.prefixes,
|
|
35
|
+
lutaml_register: Configuration.context.id,
|
|
36
|
+
)
|
|
22
37
|
end
|
|
23
38
|
|
|
24
39
|
def dimensions
|
|
25
|
-
Dimensions.new(
|
|
40
|
+
@dimensions ||= Dimensions.new(
|
|
41
|
+
dimensions: database.dimensions,
|
|
42
|
+
lutaml_register: Configuration.context.id,
|
|
43
|
+
)
|
|
26
44
|
end
|
|
27
45
|
|
|
28
46
|
def quantities
|
|
29
|
-
Quantities.new(
|
|
47
|
+
@quantities ||= Quantities.new(
|
|
48
|
+
quantities: database.quantities,
|
|
49
|
+
lutaml_register: Configuration.context.id,
|
|
50
|
+
)
|
|
30
51
|
end
|
|
31
52
|
|
|
32
53
|
def prefixes_array
|
|
@@ -39,6 +60,53 @@ module Unitsml
|
|
|
39
60
|
|
|
40
61
|
@sized_prefixes[size] = prefixes_array.select { |p| p.size == size }
|
|
41
62
|
end
|
|
63
|
+
|
|
64
|
+
def database
|
|
65
|
+
@database ||= load_database
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def load_database
|
|
71
|
+
context_id = Configuration.context.id
|
|
72
|
+
|
|
73
|
+
if ::Unitsdb.respond_to?(:database)
|
|
74
|
+
return load_unitsdb_database(context_id)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
Database.from_db(database_path, context: context_id)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def load_unitsdb_database(context_id)
|
|
81
|
+
::Unitsdb.database(context: context_id)
|
|
82
|
+
rescue ::Unitsdb::Errors::DatabaseNotFoundError,
|
|
83
|
+
::Unitsdb::Errors::DatabaseFileNotFoundError
|
|
84
|
+
Database.from_db(database_path, context: context_id)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def database_path
|
|
88
|
+
candidate_database_paths.find do |path|
|
|
89
|
+
database_files_present?(path)
|
|
90
|
+
end ||
|
|
91
|
+
File.join(unitsdb_gem_path, "vendor", "unitsdb")
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def candidate_database_paths
|
|
95
|
+
[
|
|
96
|
+
File.join(unitsdb_gem_path, "data"),
|
|
97
|
+
File.join(unitsdb_gem_path, "vendor", "unitsdb"),
|
|
98
|
+
]
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def database_files_present?(dir_path)
|
|
102
|
+
REQUIRED_DATABASE_FILES.all? do |file_name|
|
|
103
|
+
File.exist?(File.join(dir_path, file_name))
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def unitsdb_gem_path
|
|
108
|
+
Gem.loaded_specs.fetch("unitsdb").full_gem_path
|
|
109
|
+
end
|
|
42
110
|
end
|
|
43
111
|
end
|
|
44
112
|
end
|
data/lib/unitsml/utility.rb
CHANGED
|
@@ -40,6 +40,12 @@ module Unitsml
|
|
|
40
40
|
].freeze
|
|
41
41
|
|
|
42
42
|
UNKNOWN = "unknown"
|
|
43
|
+
PREFIX_SYMBOL_METHODS = {
|
|
44
|
+
ASCII: :to_asciimath,
|
|
45
|
+
unicode: :to_unicode,
|
|
46
|
+
LaTeX: :to_latex,
|
|
47
|
+
HTML: :to_html,
|
|
48
|
+
}.freeze
|
|
43
49
|
|
|
44
50
|
class << self
|
|
45
51
|
def unit_instance(unit)
|
|
@@ -139,26 +145,71 @@ module Unitsml
|
|
|
139
145
|
end
|
|
140
146
|
|
|
141
147
|
def prefix_object(prefix)
|
|
142
|
-
return
|
|
143
|
-
return
|
|
148
|
+
return nil if prefix.nil?
|
|
149
|
+
return prefix if prefix_like?(prefix)
|
|
150
|
+
|
|
151
|
+
if prefix.is_a?(String)
|
|
152
|
+
return nil unless Unitsdb.prefixes_array.any?(prefix)
|
|
153
|
+
|
|
154
|
+
return Prefix.new(prefix)
|
|
155
|
+
end
|
|
144
156
|
|
|
145
|
-
|
|
157
|
+
return Unitsdb.prefixes.find_by_id(prefix.id) if prefix.respond_to?(:id)
|
|
158
|
+
|
|
159
|
+
prefix
|
|
146
160
|
end
|
|
147
161
|
|
|
148
162
|
def combine_prefixes(p1, p2)
|
|
163
|
+
p1 = prefix_object(p1)
|
|
164
|
+
p2 = prefix_object(p2)
|
|
149
165
|
return nil if p1.nil? && p2.nil?
|
|
150
|
-
return p1
|
|
151
|
-
return p2
|
|
152
|
-
return UNKNOWN if p1
|
|
166
|
+
return prefix_symbolid(p1) if p2.nil?
|
|
167
|
+
return prefix_symbolid(p2) if p1.nil?
|
|
168
|
+
return UNKNOWN if prefix_base(p1) != prefix_base(p2)
|
|
153
169
|
|
|
154
170
|
Unitsdb.prefixes_array.each do |prefix_name|
|
|
155
171
|
p = prefix_object(prefix_name)
|
|
156
|
-
return p if p
|
|
172
|
+
return p if prefix_base(p) == prefix_base(p1) &&
|
|
173
|
+
prefix_power(p) == prefix_power(p1) + prefix_power(p2)
|
|
157
174
|
end
|
|
158
175
|
|
|
159
176
|
UNKNOWN
|
|
160
177
|
end
|
|
161
178
|
|
|
179
|
+
def prefix_like?(prefix)
|
|
180
|
+
prefix.respond_to?(:base) && prefix.respond_to?(:power) &&
|
|
181
|
+
(prefix.respond_to?(:symbolid) || prefix.respond_to?(:symbols))
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
def prefix_symbolid(prefix)
|
|
185
|
+
return prefix.symbolid if prefix.respond_to?(:symbolid)
|
|
186
|
+
|
|
187
|
+
prefix_record = resolved_prefix(prefix)
|
|
188
|
+
return unless prefix_record
|
|
189
|
+
|
|
190
|
+
prefix_record.symbols&.first&.ascii
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def prefix_base(prefix)
|
|
194
|
+
return prefix.base if prefix.respond_to?(:base)
|
|
195
|
+
|
|
196
|
+
resolved_prefix(prefix)&.base
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def prefix_power(prefix)
|
|
200
|
+
return prefix.power if prefix.respond_to?(:power)
|
|
201
|
+
|
|
202
|
+
resolved_prefix(prefix)&.power
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def resolved_prefix(prefix)
|
|
206
|
+
return prefix if prefix.nil?
|
|
207
|
+
return prefix if prefix.respond_to?(:symbols) && prefix.respond_to?(:base) && prefix.respond_to?(:power)
|
|
208
|
+
return Unitsdb.prefixes.find_by_id(prefix.id) if prefix.respond_to?(:id)
|
|
209
|
+
|
|
210
|
+
prefix
|
|
211
|
+
end
|
|
212
|
+
|
|
162
213
|
def unit(units, formula, dims, norm_text, name, options)
|
|
163
214
|
attributes = {
|
|
164
215
|
id: unit_id(norm_text),
|
|
@@ -168,7 +219,7 @@ module Unitsml
|
|
|
168
219
|
root_units: rootunits(units),
|
|
169
220
|
}
|
|
170
221
|
attributes[:dimension_url] = "##{dim_id(dims)}" if dims
|
|
171
|
-
Model::Unit.new(attributes).to_xml
|
|
222
|
+
Model::Unit.new(**attributes, lutaml_register: Configuration.context.id).to_xml
|
|
172
223
|
.force_encoding("UTF-8")
|
|
173
224
|
.gsub("<", "<")
|
|
174
225
|
.gsub(">", ">")
|
|
@@ -178,8 +229,11 @@ module Unitsml
|
|
|
178
229
|
end
|
|
179
230
|
|
|
180
231
|
def unitname(text, name)
|
|
181
|
-
name ||= unit_instance(text)
|
|
182
|
-
Model::Units::Name.new(
|
|
232
|
+
name ||= unit_en_name(unit_instance(text)) || text
|
|
233
|
+
Model::Units::Name.new(
|
|
234
|
+
name: name,
|
|
235
|
+
lutaml_register: Configuration.context.id,
|
|
236
|
+
)
|
|
183
237
|
end
|
|
184
238
|
|
|
185
239
|
def unitsymbols(formula, options)
|
|
@@ -187,31 +241,44 @@ module Unitsml
|
|
|
187
241
|
Model::Units::Symbol.new(
|
|
188
242
|
type: lang,
|
|
189
243
|
content: formula.public_send(:"to_#{lang.downcase}", options),
|
|
244
|
+
lutaml_register: Configuration.context.id,
|
|
190
245
|
)
|
|
191
246
|
end
|
|
192
247
|
end
|
|
193
248
|
|
|
194
249
|
def unitsystem(units)
|
|
195
250
|
ret = []
|
|
196
|
-
|
|
251
|
+
if units.any? { |u| !u.si_system_type? }
|
|
252
|
+
ret << Model::Units::System.new(
|
|
253
|
+
name: "not_SI",
|
|
254
|
+
type: "not_SI",
|
|
255
|
+
lutaml_register: Configuration.context.id,
|
|
256
|
+
)
|
|
257
|
+
end
|
|
197
258
|
if units.any?(&:si_system_type?)
|
|
198
259
|
if units.size == 1
|
|
199
260
|
base = units[0].downcase_system_type == "si_base"
|
|
200
261
|
base = true if units[0].unit_name == "g" && units[0]&.prefix_name == "k"
|
|
201
262
|
end
|
|
202
|
-
ret << Model::Units::System.new(
|
|
203
|
-
|
|
263
|
+
ret << Model::Units::System.new(
|
|
264
|
+
name: "SI",
|
|
265
|
+
type: (base ? "SI_base" : "SI_derived"),
|
|
266
|
+
lutaml_register: Configuration.context.id,
|
|
267
|
+
)
|
|
204
268
|
end
|
|
205
269
|
ret
|
|
206
270
|
end
|
|
207
271
|
|
|
208
272
|
def dimension(norm_text)
|
|
209
|
-
dim_id = unit_instance(norm_text)
|
|
273
|
+
dim_id = unit_dimension_id(unit_instance(norm_text))
|
|
210
274
|
return unless dim_id
|
|
211
275
|
|
|
212
276
|
dim_attrs = { id: dim_id }
|
|
213
277
|
dimid2dimensions(dim_id)&.compact&.each { |u| dimension1(u, dim_attrs) }
|
|
214
|
-
Model::Dimension.new(
|
|
278
|
+
Model::Dimension.new(
|
|
279
|
+
dim_attrs,
|
|
280
|
+
lutaml_register: Configuration.context.id,
|
|
281
|
+
).to_xml.force_encoding("UTF-8")
|
|
215
282
|
end
|
|
216
283
|
|
|
217
284
|
def dimension1(dim, dims_hash)
|
|
@@ -220,6 +287,7 @@ module Unitsml
|
|
|
220
287
|
dims_hash[underscore(dim_name).to_sym] = dim_klass.new(
|
|
221
288
|
symbol: dim[:symbol],
|
|
222
289
|
power_numerator: float_to_display(dim[:exponent]),
|
|
290
|
+
lutaml_register: Configuration.context.id,
|
|
223
291
|
)
|
|
224
292
|
end
|
|
225
293
|
|
|
@@ -250,23 +318,44 @@ module Unitsml
|
|
|
250
318
|
def prefixes(units, options)
|
|
251
319
|
uniq_prefixes = units.filter_map(&:prefix).uniq(&:prefix_name)
|
|
252
320
|
uniq_prefixes.map do |prefix|
|
|
253
|
-
|
|
254
|
-
prefix_power: prefix&.power, id: prefix&.id }
|
|
255
|
-
type_and_methods = { ASCII: :to_asciimath, unicode: :to_unicode,
|
|
256
|
-
LaTeX: :to_latex, HTML: :to_html }
|
|
257
|
-
prefix_attrs[:name] = Model::Prefixes::Name.new(content: prefix&.name)
|
|
258
|
-
prefix_attrs[:symbol] = type_and_methods.map do |type, method_name|
|
|
259
|
-
Model::Prefixes::Symbol.new(
|
|
260
|
-
type: type,
|
|
261
|
-
content: prefix&.public_send(method_name, options),
|
|
262
|
-
)
|
|
263
|
-
end
|
|
264
|
-
Model::Prefix.new(prefix_attrs).to_xml.force_encoding("UTF-8").gsub(
|
|
265
|
-
"&", "&"
|
|
266
|
-
)
|
|
321
|
+
prefix_xml(prefix, options)
|
|
267
322
|
end.join("\n")
|
|
268
323
|
end
|
|
269
324
|
|
|
325
|
+
def prefix_xml(prefix, options)
|
|
326
|
+
Model::Prefix.new(
|
|
327
|
+
prefix_attributes(prefix, options),
|
|
328
|
+
lutaml_register: Configuration.context.id,
|
|
329
|
+
).to_xml.force_encoding("UTF-8").gsub("&", "&")
|
|
330
|
+
end
|
|
331
|
+
|
|
332
|
+
def prefix_attributes(prefix, options)
|
|
333
|
+
{
|
|
334
|
+
prefix_base: prefix&.base,
|
|
335
|
+
prefix_power: prefix&.power,
|
|
336
|
+
id: prefix&.id,
|
|
337
|
+
name: prefix_name(prefix),
|
|
338
|
+
symbol: prefix_symbols(prefix, options),
|
|
339
|
+
}
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
def prefix_name(prefix)
|
|
343
|
+
Model::Prefixes::Name.new(
|
|
344
|
+
content: prefix&.name,
|
|
345
|
+
lutaml_register: Configuration.context.id,
|
|
346
|
+
)
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
def prefix_symbols(prefix, options)
|
|
350
|
+
PREFIX_SYMBOL_METHODS.map do |type, method_name|
|
|
351
|
+
Model::Prefixes::Symbol.new(
|
|
352
|
+
type: type,
|
|
353
|
+
content: prefix&.public_send(method_name, options),
|
|
354
|
+
lutaml_register: Configuration.context.id,
|
|
355
|
+
)
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
|
|
270
359
|
def rootunits(units)
|
|
271
360
|
return if units.size == 1 && !units[0].prefix
|
|
272
361
|
|
|
@@ -275,9 +364,15 @@ module Unitsml
|
|
|
275
364
|
attributes[:prefix] = unit.prefix_name if unit.prefix
|
|
276
365
|
unit.power_numerator && unit.power_numerator != "1" and
|
|
277
366
|
attributes[:power_numerator] = unit.power_numerator.raw_value
|
|
278
|
-
Model::Units::EnumeratedRootUnit.new(
|
|
367
|
+
Model::Units::EnumeratedRootUnit.new(
|
|
368
|
+
**attributes,
|
|
369
|
+
lutaml_register: Configuration.context.id,
|
|
370
|
+
)
|
|
279
371
|
end
|
|
280
|
-
Model::Units::RootUnits.new(
|
|
372
|
+
Model::Units::RootUnits.new(
|
|
373
|
+
enumerated_root_unit: enum_root_units,
|
|
374
|
+
lutaml_register: Configuration.context.id,
|
|
375
|
+
)
|
|
281
376
|
end
|
|
282
377
|
|
|
283
378
|
def unit_id(text)
|
|
@@ -288,7 +383,7 @@ module Unitsml
|
|
|
288
383
|
end
|
|
289
384
|
|
|
290
385
|
def format_unit_id(unit, text)
|
|
291
|
-
return unit
|
|
386
|
+
return unit_nist_id(unit)&.gsub("'", "_") if unit
|
|
292
387
|
|
|
293
388
|
text&.gsub("*", ".")&.gsub("^", "")
|
|
294
389
|
end
|
|
@@ -298,7 +393,10 @@ module Unitsml
|
|
|
298
393
|
|
|
299
394
|
dim_attrs = { id: dim_id(dims) }
|
|
300
395
|
dims.map { |u| dimension1(u, dim_attrs) }
|
|
301
|
-
Model::Dimension.new(
|
|
396
|
+
Model::Dimension.new(
|
|
397
|
+
**dim_attrs,
|
|
398
|
+
lutaml_register: Configuration.context.id,
|
|
399
|
+
).to_xml.force_encoding("UTF-8")
|
|
302
400
|
end
|
|
303
401
|
|
|
304
402
|
def quantity(normtext, instance)
|
|
@@ -307,10 +405,36 @@ module Unitsml
|
|
|
307
405
|
|
|
308
406
|
model_quantity_xml(
|
|
309
407
|
instance || unit.quantity_references&.first&.id,
|
|
310
|
-
"##{unit
|
|
408
|
+
"##{unit_dimension_id(unit)}",
|
|
311
409
|
)
|
|
312
410
|
end
|
|
313
411
|
|
|
412
|
+
def unit_nist_id(unit)
|
|
413
|
+
return unless unit
|
|
414
|
+
return unit.nist_id if unit.respond_to?(:nist_id)
|
|
415
|
+
|
|
416
|
+
unit.identifiers&.find { |identifier| identifier.type == "nist" }&.id
|
|
417
|
+
end
|
|
418
|
+
|
|
419
|
+
def unit_en_name(unit)
|
|
420
|
+
return unless unit
|
|
421
|
+
return unit.en_name if unit.respond_to?(:en_name)
|
|
422
|
+
|
|
423
|
+
unit.names&.find { |name| name.lang == "en" }&.value
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
def unit_dimension_id(unit)
|
|
427
|
+
return unless unit
|
|
428
|
+
return unit.dimension_url if unit.respond_to?(:dimension_url)
|
|
429
|
+
|
|
430
|
+
unit.dimension_reference&.id ||
|
|
431
|
+
quantity_dimension_id(quantity_instance(unit.quantity_references&.first&.id))
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
def quantity_dimension_id(quantity)
|
|
435
|
+
quantity&.dimension_reference&.id
|
|
436
|
+
end
|
|
437
|
+
|
|
314
438
|
def unit_or_quantity(unit, quantity)
|
|
315
439
|
(unit && unit.quantity_references.size == 1) ||
|
|
316
440
|
quantity_instance(quantity)
|
|
@@ -321,6 +445,7 @@ module Unitsml
|
|
|
321
445
|
id: id,
|
|
322
446
|
name: quantity_name(id),
|
|
323
447
|
dimension_url: url,
|
|
448
|
+
lutaml_register: Configuration.context.id,
|
|
324
449
|
).to_xml.force_encoding("UTF-8")
|
|
325
450
|
end
|
|
326
451
|
|
|
@@ -328,7 +453,7 @@ module Unitsml
|
|
|
328
453
|
quantity_instance(id)&.names&.filter_map do |name|
|
|
329
454
|
next unless name.lang == "en"
|
|
330
455
|
|
|
331
|
-
Model::Quantities::Name.new(content: name.value)
|
|
456
|
+
Model::Quantities::Name.new(content: name.value, lutaml_register: Configuration.context.id)
|
|
332
457
|
end
|
|
333
458
|
end
|
|
334
459
|
|
data/lib/unitsml/version.rb
CHANGED
data/lib/unitsml.rb
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "lutaml/model"
|
|
4
|
-
require "
|
|
4
|
+
require "mml"
|
|
5
5
|
|
|
6
6
|
module Unitsml
|
|
7
7
|
module_function
|
|
8
8
|
|
|
9
9
|
autoload :Dimension, "unitsml/dimension"
|
|
10
|
+
autoload :Configuration, "unitsml/configuration"
|
|
10
11
|
autoload :Errors, "unitsml/errors"
|
|
11
12
|
autoload :Extender, "unitsml/extender"
|
|
12
13
|
autoload :Fenced, "unitsml/fenced"
|
|
13
14
|
autoload :FencedNumeric, "unitsml/fenced_numeric"
|
|
14
15
|
autoload :Formula, "unitsml/formula"
|
|
15
16
|
autoload :IntermediateExpRules, "unitsml/intermediate_exp_rules"
|
|
17
|
+
autoload :MathmlHelper, "unitsml/mathml_helper"
|
|
16
18
|
autoload :Model, "unitsml/model"
|
|
17
19
|
autoload :Namespace, "unitsml/namespace"
|
|
18
20
|
autoload :Number, "unitsml/number"
|
|
@@ -26,54 +28,11 @@ module Unitsml
|
|
|
26
28
|
autoload :Utility, "unitsml/utility"
|
|
27
29
|
autoload :VERSION, "unitsml/version"
|
|
28
30
|
|
|
29
|
-
REGISTER_ID = :unitsml_ruby
|
|
30
|
-
|
|
31
31
|
def parse(string)
|
|
32
32
|
Unitsml::Parser.new(string).parse
|
|
33
33
|
end
|
|
34
|
-
|
|
35
|
-
def register
|
|
36
|
-
@register ||= Lutaml::Model::GlobalRegister.lookup(REGISTER_ID)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def register_model(klass, id:)
|
|
40
|
-
register.register_model(klass, id: id)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def get_class_from_register(class_name)
|
|
44
|
-
register.get_class(class_name)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def register_type_substitution(from:, to:)
|
|
48
|
-
register.register_global_type_substitution(
|
|
49
|
-
from_type: from,
|
|
50
|
-
to_type: to,
|
|
51
|
-
)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
Lutaml::Model::GlobalRegister.register(
|
|
56
|
-
Lutaml::Model::Register.new(Unitsml::REGISTER_ID),
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
Unitsdb::Unit => Unitsml::Unitsdb::Unit,
|
|
61
|
-
Unitsdb::Units => Unitsml::Unitsdb::Units,
|
|
62
|
-
Unitsdb::Prefixes => Unitsml::Unitsdb::Prefixes,
|
|
63
|
-
Unitsdb::Dimension => Unitsml::Unitsdb::Dimension,
|
|
64
|
-
Unitsdb::PrefixReference => Unitsml::Unitsdb::PrefixReference,
|
|
65
|
-
Unitsdb::DimensionDetails => Unitsml::Unitsdb::DimensionQuantity,
|
|
66
|
-
}.each do |key, value|
|
|
67
|
-
Unitsml.register_type_substitution(from: key, to: value)
|
|
68
34
|
end
|
|
69
35
|
|
|
70
|
-
[
|
|
71
|
-
[Unitsml::Unitsdb::Dimensions, :unitsdb_dimensions],
|
|
72
|
-
[Unitsml::Unitsdb::Prefixes, :unitsdb_prefixes],
|
|
73
|
-
[Unitsml::Unitsdb::Quantities, :unitsdb_quantities],
|
|
74
|
-
[Unitsml::Unitsdb::Units, :unitsdb_units],
|
|
75
|
-
].each { |klass, id| Unitsml.register_model(klass, id: id) }
|
|
76
|
-
|
|
77
36
|
Lutaml::Model::Config.configure do |config|
|
|
78
37
|
config.xml_adapter_type = RUBY_ENGINE == "opal" ? :oga : :ox
|
|
79
38
|
end
|
data/unitsml.gemspec
CHANGED
|
@@ -30,11 +30,11 @@ Gem::Specification.new do |spec|
|
|
|
30
30
|
|
|
31
31
|
spec.bindir = "exe"
|
|
32
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
|
-
spec.require_paths = ["lib"
|
|
33
|
+
spec.require_paths = ["lib"]
|
|
34
34
|
|
|
35
35
|
spec.add_dependency "htmlentities"
|
|
36
36
|
spec.add_dependency "lutaml-model", "~> 0.8.0"
|
|
37
|
-
spec.add_dependency "mml"
|
|
37
|
+
spec.add_dependency "mml", "~> 2.3.6"
|
|
38
38
|
spec.add_dependency "parslet"
|
|
39
|
-
spec.add_dependency "unitsdb", "~> 2.2.
|
|
39
|
+
spec.add_dependency "unitsdb", "~> 2.2.2"
|
|
40
40
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unitsml
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.4
|
|
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: htmlentities
|
|
@@ -42,16 +42,16 @@ dependencies:
|
|
|
42
42
|
name: mml
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version:
|
|
47
|
+
version: 2.3.6
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - "~>"
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
54
|
+
version: 2.3.6
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: parslet
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -72,14 +72,14 @@ dependencies:
|
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 2.2.
|
|
75
|
+
version: 2.2.2
|
|
76
76
|
type: :runtime
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
80
|
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: 2.2.
|
|
82
|
+
version: 2.2.2
|
|
83
83
|
description: Library to work with UnitsML in Ruby
|
|
84
84
|
email:
|
|
85
85
|
- open.source@ribose.com
|
|
@@ -105,15 +105,18 @@ files:
|
|
|
105
105
|
- docs/README.adoc
|
|
106
106
|
- docs/navigation.adoc
|
|
107
107
|
- lib/unitsml.rb
|
|
108
|
+
- lib/unitsml/configuration.rb
|
|
108
109
|
- lib/unitsml/dimension.rb
|
|
109
110
|
- lib/unitsml/errors.rb
|
|
110
111
|
- lib/unitsml/errors/base_error.rb
|
|
112
|
+
- lib/unitsml/errors/opal_payload_not_bundled_error.rb
|
|
111
113
|
- lib/unitsml/errors/plurimath_load_error.rb
|
|
112
114
|
- lib/unitsml/extender.rb
|
|
113
115
|
- lib/unitsml/fenced.rb
|
|
114
116
|
- lib/unitsml/fenced_numeric.rb
|
|
115
117
|
- lib/unitsml/formula.rb
|
|
116
118
|
- lib/unitsml/intermediate_exp_rules.rb
|
|
119
|
+
- lib/unitsml/mathml_helper.rb
|
|
117
120
|
- lib/unitsml/model.rb
|
|
118
121
|
- lib/unitsml/model/dimension.rb
|
|
119
122
|
- lib/unitsml/model/dimension_quantities.rb
|
|
@@ -149,13 +152,13 @@ files:
|
|
|
149
152
|
- lib/unitsml/transform.rb
|
|
150
153
|
- lib/unitsml/unit.rb
|
|
151
154
|
- lib/unitsml/unitsdb.rb
|
|
155
|
+
- lib/unitsml/unitsdb/database.rb
|
|
152
156
|
- lib/unitsml/unitsdb/dimension.rb
|
|
153
|
-
- lib/unitsml/unitsdb/
|
|
157
|
+
- lib/unitsml/unitsdb/dimension_details.rb
|
|
154
158
|
- lib/unitsml/unitsdb/dimensions.rb
|
|
155
159
|
- lib/unitsml/unitsdb/prefix_reference.rb
|
|
156
160
|
- lib/unitsml/unitsdb/prefixes.rb
|
|
157
161
|
- lib/unitsml/unitsdb/quantities.rb
|
|
158
|
-
- lib/unitsml/unitsdb/si_derived_base.rb
|
|
159
162
|
- lib/unitsml/unitsdb/unit.rb
|
|
160
163
|
- lib/unitsml/unitsdb/units.rb
|
|
161
164
|
- lib/unitsml/utility.rb
|
|
@@ -171,7 +174,6 @@ post_install_message:
|
|
|
171
174
|
rdoc_options: []
|
|
172
175
|
require_paths:
|
|
173
176
|
- lib
|
|
174
|
-
- unitsdb/**/*.yaml
|
|
175
177
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
178
|
requirements:
|
|
177
179
|
- - ">="
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Unitsml
|
|
4
|
-
module Unitsdb
|
|
5
|
-
class SiDerivedBase < ::Unitsdb::SiDerivedBase
|
|
6
|
-
def prefix_reference=(value)
|
|
7
|
-
return super if value.nil?
|
|
8
|
-
return super if value.is_a?(PrefixReference)
|
|
9
|
-
|
|
10
|
-
super(PrefixReference.new(value.to_hash))
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|