unitsml 0.4.7 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +8 -0
  3. data/.github/workflows/release.yml +7 -1
  4. data/.rubocop.yml +18 -0
  5. data/.rubocop_todo.yml +498 -0
  6. data/Gemfile +16 -11
  7. data/Rakefile +5 -3
  8. data/bin/console +4 -3
  9. data/docs/README.adoc +106 -4
  10. data/lib/unitsml/dimension.rb +49 -35
  11. data/lib/unitsml/errors/base_error.rb +8 -0
  12. data/lib/unitsml/errors/plurimath_load_error.rb +1 -1
  13. data/lib/unitsml/errors.rb +8 -0
  14. data/lib/unitsml/extender.rb +21 -16
  15. data/lib/unitsml/fenced.rb +97 -0
  16. data/lib/unitsml/fenced_numeric.rb +13 -0
  17. data/lib/unitsml/formula.rb +46 -33
  18. data/lib/unitsml/intermediate_exp_rules.rb +76 -0
  19. data/lib/unitsml/model/dimension.rb +4 -14
  20. data/lib/unitsml/model/dimension_quantities/quantity.rb +2 -0
  21. data/lib/unitsml/model/dimension_quantities.rb +17 -0
  22. data/lib/unitsml/model/prefix.rb +4 -8
  23. data/lib/unitsml/model/prefixes/name.rb +5 -4
  24. data/lib/unitsml/model/prefixes/symbol.rb +3 -2
  25. data/lib/unitsml/model/prefixes.rb +10 -0
  26. data/lib/unitsml/model/quantities/name.rb +4 -3
  27. data/lib/unitsml/model/quantities.rb +9 -0
  28. data/lib/unitsml/model/quantity.rb +5 -7
  29. data/lib/unitsml/model/unit.rb +4 -9
  30. data/lib/unitsml/model/units/enumerated_root_unit.rb +1 -0
  31. data/lib/unitsml/model/units/name.rb +4 -3
  32. data/lib/unitsml/model/units/root_units.rb +3 -2
  33. data/lib/unitsml/model/units/symbol.rb +2 -1
  34. data/lib/unitsml/model/units/system.rb +4 -3
  35. data/lib/unitsml/model/units.rb +13 -0
  36. data/lib/unitsml/model.rb +15 -0
  37. data/lib/unitsml/namespace.rb +8 -0
  38. data/lib/unitsml/number.rb +79 -0
  39. data/lib/unitsml/parse.rb +30 -38
  40. data/lib/unitsml/parser.rb +27 -13
  41. data/lib/unitsml/prefix.rb +17 -17
  42. data/lib/unitsml/sqrt.rb +3 -3
  43. data/lib/unitsml/transform.rb +143 -50
  44. data/lib/unitsml/unit.rb +67 -37
  45. data/lib/unitsml/unitsdb/dimension.rb +14 -20
  46. data/lib/unitsml/unitsdb/dimension_quantity.rb +2 -6
  47. data/lib/unitsml/unitsdb/dimensions.rb +3 -9
  48. data/lib/unitsml/unitsdb/prefix_reference.rb +23 -0
  49. data/lib/unitsml/unitsdb/prefixes.rb +17 -5
  50. data/lib/unitsml/unitsdb/quantities.rb +4 -4
  51. data/lib/unitsml/unitsdb/unit.rb +21 -0
  52. data/lib/unitsml/unitsdb/units.rb +19 -18
  53. data/lib/unitsml/unitsdb.rb +14 -5
  54. data/lib/unitsml/utility.rb +133 -103
  55. data/lib/unitsml/version.rb +3 -1
  56. data/lib/unitsml.rb +71 -35
  57. data/unitsdb/Gemfile +6 -0
  58. data/unitsdb/LICENSE.md +53 -0
  59. data/unitsdb/README.adoc +1253 -0
  60. data/unitsdb/RELEASE-NOTES.adoc +269 -0
  61. data/unitsdb/dimensions.yaml +1607 -602
  62. data/unitsdb/prefixes.yaml +842 -301
  63. data/unitsdb/quantities.yaml +3706 -2458
  64. data/unitsdb/scales.yaml +97 -0
  65. data/unitsdb/schemas/README.md +159 -0
  66. data/unitsdb/schemas/dimensions-schema.yaml +153 -0
  67. data/unitsdb/schemas/prefixes-schema.yaml +155 -0
  68. data/unitsdb/schemas/quantities-schema.yaml +117 -0
  69. data/unitsdb/schemas/scales-schema.yaml +106 -0
  70. data/unitsdb/schemas/unit_systems-schema.yaml +116 -0
  71. data/unitsdb/schemas/units-schema.yaml +215 -0
  72. data/unitsdb/spec/units_spec.rb +13 -10
  73. data/unitsdb/unit_systems.yaml +77 -15
  74. data/unitsdb/units.yaml +13517 -9974
  75. data/unitsdb/validate_schemas.rb +203 -0
  76. data/unitsml.gemspec +4 -1
  77. metadata +47 -7
  78. data/lib/unitsml/error.rb +0 -8
  79. data/unitsdb/docs/README.adoc +0 -12
  80. data/unitsdb/docs/navigation.adoc +0 -7
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Unitsml
2
- VERSION = "0.4.7"
4
+ VERSION = '0.6.0'
3
5
  end
data/lib/unitsml.rb CHANGED
@@ -1,43 +1,79 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'lutaml/model'
4
+ require 'unitsdb'
5
+
3
6
  module Unitsml
4
- UNITSML_NS = "https://schema.unitsml.org/unitsml/1.0".freeze
7
+ module_function
8
+
9
+ autoload :Dimension, 'unitsml/dimension'
10
+ autoload :Errors, 'unitsml/errors'
11
+ autoload :Extender, 'unitsml/extender'
12
+ autoload :Fenced, 'unitsml/fenced'
13
+ autoload :FencedNumeric, 'unitsml/fenced_numeric'
14
+ autoload :Formula, 'unitsml/formula'
15
+ autoload :IntermediateExpRules, 'unitsml/intermediate_exp_rules'
16
+ autoload :Model, 'unitsml/model'
17
+ autoload :Namespace, 'unitsml/namespace'
18
+ autoload :Number, 'unitsml/number'
19
+ autoload :Parse, 'unitsml/parse'
20
+ autoload :Parser, 'unitsml/parser'
21
+ autoload :Prefix, 'unitsml/prefix'
22
+ autoload :Sqrt, 'unitsml/sqrt'
23
+ autoload :Transform, 'unitsml/transform'
24
+ autoload :Unit, 'unitsml/unit'
25
+ autoload :Unitsdb, 'unitsml/unitsdb'
26
+ autoload :Utility, 'unitsml/utility'
27
+ autoload :VERSION, 'unitsml/version'
5
28
 
6
- def self.parse(string)
29
+ REGISTER_ID = :unitsml_ruby
30
+
31
+ def parse(string)
7
32
  Unitsml::Parser.new(string).parse
8
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)
9
68
  end
10
69
 
11
- require "unitsml/error"
12
- require "unitsml/sqrt"
13
- require "unitsml/unit"
14
- require "unitsml/parse"
15
- require "unitsml/parser"
16
- require "unitsml/prefix"
17
- require "unitsml/formula"
18
- require "unitsml/version"
19
- require "unitsml/unitsdb"
20
- require "unitsml/extender"
21
- require "unitsml/dimension"
22
- require "unitsml/transform"
23
- require "unitsml/unitsdb/units"
24
- require "unitsml/unitsdb/prefixes"
25
- require "unitsml/unitsdb/dimension"
26
- require "unitsml/unitsdb/dimensions"
27
- require "unitsml/unitsdb/quantities"
28
- require "unitsml/unitsdb/dimension_quantity"
29
- require "unitsdb/config"
30
- Unitsdb::Config.models = {
31
- units: Unitsml::Unitsdb::Units,
32
- prefixes: Unitsml::Unitsdb::Prefixes,
33
- dimension: Unitsml::Unitsdb::Dimension,
34
- dimensions: Unitsml::Unitsdb::Dimensions,
35
- quantities: Unitsml::Unitsdb::Quantities,
36
- dimension_quantity: Unitsml::Unitsdb::DimensionQuantity,
37
- }
38
- require "unitsdb"
39
-
40
- DEFAULT_XML_ADAPTER = RUBY_ENGINE == "opal" ? :oga : :ox
41
- Lutaml::Model::Config.xml_adapter_type = DEFAULT_XML_ADAPTER
42
- # TODO: Remove Moxml adapter assignment when Lutaml::Model utilizes Moxml completely
43
- Moxml::Config.default_adapter = DEFAULT_ADAPTER
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
+ Lutaml::Model::Config.configure do |config|
78
+ config.xml_adapter_type = RUBY_ENGINE == 'opal' ? :oga : :ox
79
+ end
data/unitsdb/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "json-schema"
6
+ gem "unitsdb"
@@ -0,0 +1,53 @@
1
+ Licenses & Copyright
2
+ ====================
3
+
4
+ This license file adheres to the formatting guidelines of
5
+ [readable-licenses](https://github.com/nevir/readable-licenses).
6
+
7
+
8
+ CalConnect MIT License
9
+ ----------------------
10
+
11
+ Copyright 2020-2025, CalConnect
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
14
+ this software and associated documentation files (the “Software”), to deal in
15
+ the Software without restriction, including without limitation the rights to
16
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
17
+ the Software, and to permit persons to whom the Software is furnished to do so,
18
+ subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
25
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
26
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
27
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+
30
+
31
+ NIST Public Domain Notice (SPDX: NIST-PD)
32
+ -----------------------------------------
33
+
34
+ This software was developed by employees of the National Institute of Standards
35
+ and Technology (NIST), and others.
36
+
37
+ This software has been contributed to the public domain.
38
+
39
+ Pursuant to title 15 Untied States Code Section 105, works of NIST employees are
40
+ not subject to copyright protection in the United States and are considered to
41
+ be in the public domain.
42
+
43
+ As a result, a formal license is not needed to use this software.
44
+
45
+ This software is provided "AS IS."
46
+
47
+ NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING,
48
+ WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
49
+ PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY.
50
+
51
+ NIST does not warrant or make any representations regarding the use of the
52
+ software or the results thereof, including but not limited to the correctness,
53
+ accuracy, reliability or usefulness of this software.