unitsml 0.5.1 → 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.
- checksums.yaml +4 -4
- data/.github/workflows/rake.yml +8 -0
- data/.github/workflows/release.yml +7 -1
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +498 -0
- data/Gemfile +16 -11
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/docs/README.adoc +2 -2
- data/lib/unitsml/dimension.rb +49 -35
- data/lib/unitsml/errors/base_error.rb +8 -0
- data/lib/unitsml/errors/plurimath_load_error.rb +1 -1
- data/lib/unitsml/errors.rb +8 -0
- data/lib/unitsml/extender.rb +21 -16
- data/lib/unitsml/fenced.rb +30 -10
- data/lib/unitsml/fenced_numeric.rb +13 -0
- data/lib/unitsml/formula.rb +29 -29
- data/lib/unitsml/intermediate_exp_rules.rb +58 -17
- data/lib/unitsml/model/dimension.rb +4 -14
- data/lib/unitsml/model/dimension_quantities/quantity.rb +2 -0
- data/lib/unitsml/model/dimension_quantities.rb +17 -0
- data/lib/unitsml/model/prefix.rb +4 -8
- data/lib/unitsml/model/prefixes/name.rb +5 -4
- data/lib/unitsml/model/prefixes/symbol.rb +3 -2
- data/lib/unitsml/model/prefixes.rb +10 -0
- data/lib/unitsml/model/quantities/name.rb +4 -3
- data/lib/unitsml/model/quantities.rb +9 -0
- data/lib/unitsml/model/quantity.rb +5 -7
- data/lib/unitsml/model/unit.rb +4 -9
- data/lib/unitsml/model/units/enumerated_root_unit.rb +1 -0
- data/lib/unitsml/model/units/name.rb +4 -3
- data/lib/unitsml/model/units/root_units.rb +3 -2
- data/lib/unitsml/model/units/symbol.rb +2 -1
- data/lib/unitsml/model/units/system.rb +4 -3
- data/lib/unitsml/model/units.rb +13 -0
- data/lib/unitsml/model.rb +15 -0
- data/lib/unitsml/namespace.rb +8 -0
- data/lib/unitsml/number.rb +79 -0
- data/lib/unitsml/parse.rb +20 -19
- data/lib/unitsml/parser.rb +13 -14
- data/lib/unitsml/prefix.rb +10 -10
- data/lib/unitsml/sqrt.rb +3 -3
- data/lib/unitsml/transform.rb +133 -71
- data/lib/unitsml/unit.rb +41 -33
- data/lib/unitsml/unitsdb/dimension.rb +3 -3
- data/lib/unitsml/unitsdb/dimensions.rb +2 -4
- data/lib/unitsml/unitsdb/prefixes.rb +0 -2
- data/lib/unitsml/unitsdb/quantities.rb +0 -2
- data/lib/unitsml/unitsdb/unit.rb +2 -2
- data/lib/unitsml/unitsdb/units.rb +2 -4
- data/lib/unitsml/unitsdb.rb +14 -9
- data/lib/unitsml/utility.rb +111 -73
- data/lib/unitsml/version.rb +3 -1
- data/lib/unitsml.rb +51 -33
- data/unitsdb/Gemfile +6 -0
- data/unitsdb/README.adoc +193 -11
- data/unitsdb/dimensions.yaml +360 -8
- data/unitsdb/prefixes.yaml +104 -4
- data/unitsdb/quantities.yaml +602 -0
- data/unitsdb/schemas/dimensions-schema.yaml +2 -6
- data/unitsdb/schemas/prefixes-schema.yaml +2 -6
- data/unitsdb/schemas/quantities-schema.yaml +2 -5
- data/unitsdb/schemas/scales-schema.yaml +2 -5
- data/unitsdb/schemas/unit_systems-schema.yaml +2 -6
- data/unitsdb/schemas/units-schema.yaml +2 -6
- data/unitsdb/spec/units_spec.rb +3 -1
- data/unitsdb/unit_systems.yaml +4 -0
- data/unitsdb/units.yaml +957 -6
- data/unitsdb/validate_schemas.rb +32 -37
- data/unitsml.gemspec +3 -1
- metadata +29 -17
- data/lib/unitsml/error.rb +0 -8
data/unitsdb/validate_schemas.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
5
|
-
require
|
|
6
|
-
require
|
|
3
|
+
require "yaml"
|
|
4
|
+
require "json-schema"
|
|
5
|
+
require "json"
|
|
6
|
+
require "pathname"
|
|
7
7
|
|
|
8
8
|
class SchemaValidator
|
|
9
9
|
def initialize
|
|
10
|
-
@schemas_dir = Pathname.new(
|
|
10
|
+
@schemas_dir = Pathname.new("schemas")
|
|
11
11
|
@errors_found = false
|
|
12
12
|
end
|
|
13
13
|
|
|
@@ -17,19 +17,19 @@ class SchemaValidator
|
|
|
17
17
|
|
|
18
18
|
# Define the mapping of YAML files to their schemas
|
|
19
19
|
file_schema_map = {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
"units.yaml" => "units-schema.yaml",
|
|
21
|
+
"quantities.yaml" => "quantities-schema.yaml",
|
|
22
|
+
"scales.yaml" => "scales-schema.yaml",
|
|
23
|
+
"prefixes.yaml" => "prefixes-schema.yaml",
|
|
24
|
+
"unit_systems.yaml" => "unit_systems-schema.yaml",
|
|
25
|
+
"dimensions.yaml" => "dimensions-schema.yaml",
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
file_schema_map.each do |yaml_file, schema_file|
|
|
29
29
|
validate_file(yaml_file, schema_file)
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
puts "\n
|
|
32
|
+
puts "\n#{'=' * 50}"
|
|
33
33
|
if @errors_found
|
|
34
34
|
puts "❌ Validation completed with errors"
|
|
35
35
|
exit 1
|
|
@@ -68,8 +68,8 @@ class SchemaValidator
|
|
|
68
68
|
|
|
69
69
|
# Validate
|
|
70
70
|
errors = JSON::Validator.fully_validate(schema_json, yaml_data,
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
errors_as_objects: true,
|
|
72
|
+
validate_schema: true)
|
|
73
73
|
|
|
74
74
|
if errors.empty?
|
|
75
75
|
puts "✅ #{yaml_file} - Valid"
|
|
@@ -84,17 +84,16 @@ class SchemaValidator
|
|
|
84
84
|
|
|
85
85
|
# Try to provide more context about the location
|
|
86
86
|
if error[:fragment] && !error[:fragment].empty?
|
|
87
|
-
path_parts = error[:fragment].split(
|
|
87
|
+
path_parts = error[:fragment].split("/")
|
|
88
88
|
puts " Location: #{describe_path(path_parts, yaml_data)}"
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
# Show the failing value if available
|
|
92
|
-
if error[:failed_attribute] && error[:failed_attribute] !=
|
|
92
|
+
if error[:failed_attribute] && error[:failed_attribute] != "schema"
|
|
93
93
|
puts " Failed validation: #{error[:failed_attribute]}"
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
|
-
|
|
98
97
|
rescue YAML::SyntaxError => e
|
|
99
98
|
puts "❌ YAML syntax error in #{yaml_file}:"
|
|
100
99
|
puts " Line #{e.line}: #{e.problem}"
|
|
@@ -114,9 +113,9 @@ class SchemaValidator
|
|
|
114
113
|
description_parts = []
|
|
115
114
|
|
|
116
115
|
path_parts.each do |part|
|
|
117
|
-
next if part.empty? || part ==
|
|
116
|
+
next if part.empty? || part == "#"
|
|
118
117
|
|
|
119
|
-
if
|
|
118
|
+
if /^\d+$/.match?(part)
|
|
120
119
|
# Array index
|
|
121
120
|
index = part.to_i
|
|
122
121
|
if current.is_a?(Array) && current[index]
|
|
@@ -126,45 +125,41 @@ class SchemaValidator
|
|
|
126
125
|
description_parts << "index #{index} (out of bounds)"
|
|
127
126
|
break
|
|
128
127
|
end
|
|
129
|
-
|
|
128
|
+
elsif current.is_a?(Hash) && current.key?(part)
|
|
130
129
|
# Object property
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
break
|
|
137
|
-
end
|
|
130
|
+
description_parts << "property '#{part}'"
|
|
131
|
+
current = current[part]
|
|
132
|
+
else
|
|
133
|
+
description_parts << "missing property '#{part}'"
|
|
134
|
+
break
|
|
138
135
|
end
|
|
139
136
|
end
|
|
140
137
|
|
|
141
|
-
description_parts.join(
|
|
138
|
+
description_parts.join(" -> ")
|
|
142
139
|
end
|
|
143
140
|
end
|
|
144
141
|
|
|
145
142
|
# Additional helper methods for detailed error reporting
|
|
146
143
|
class SchemaValidator
|
|
147
144
|
def self.check_dependencies
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
exit 1
|
|
154
|
-
end
|
|
145
|
+
require "json-schema"
|
|
146
|
+
rescue LoadError
|
|
147
|
+
puts "❌ Missing required gem: json-schema"
|
|
148
|
+
puts " Install with: gem install json-schema"
|
|
149
|
+
exit 1
|
|
155
150
|
end
|
|
156
151
|
|
|
157
152
|
def self.run_with_options
|
|
158
153
|
check_dependencies
|
|
159
154
|
|
|
160
|
-
if ARGV.include?(
|
|
155
|
+
if ARGV.include?("--help") || ARGV.include?("-h")
|
|
161
156
|
show_help
|
|
162
157
|
exit 0
|
|
163
158
|
end
|
|
164
159
|
|
|
165
160
|
validator = new
|
|
166
161
|
|
|
167
|
-
if ARGV.include?(
|
|
162
|
+
if ARGV.include?("--verbose") || ARGV.include?("-v")
|
|
168
163
|
puts "Ruby version: #{RUBY_VERSION}"
|
|
169
164
|
puts "JSON Schema gem version: #{JSON::Schema::VERSION}"
|
|
170
165
|
puts "Working directory: #{Dir.pwd}"
|
data/unitsml.gemspec
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'lib/unitsml/version'
|
|
2
4
|
|
|
3
5
|
Gem::Specification.new do |spec|
|
|
@@ -28,8 +30,8 @@ Gem::Specification.new do |spec|
|
|
|
28
30
|
spec.require_paths = ['lib', 'unitsdb/**/*.yaml']
|
|
29
31
|
|
|
30
32
|
spec.add_dependency 'htmlentities'
|
|
33
|
+
spec.add_dependency 'lutaml-model', '~> 0.8.0'
|
|
31
34
|
spec.add_dependency 'mml'
|
|
32
35
|
spec.add_dependency 'parslet'
|
|
33
36
|
spec.add_dependency 'unitsdb', '~> 2.0'
|
|
34
|
-
spec.add_dependency 'lutaml-model', '~> 0.7.6'
|
|
35
37
|
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.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-04-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: htmlentities
|
|
@@ -25,21 +25,21 @@ dependencies:
|
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: lutaml-model
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 0.8.0
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
40
|
+
version: 0.8.0
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: mml
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - ">="
|
|
@@ -53,33 +53,33 @@ dependencies:
|
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: parslet
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - ">="
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '0'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
70
|
+
name: unitsdb
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: 0
|
|
75
|
+
version: '2.0'
|
|
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: 0
|
|
82
|
+
version: '2.0'
|
|
83
83
|
description: Library to work with UnitsML in Ruby
|
|
84
84
|
email:
|
|
85
85
|
- open.source@ribose.com
|
|
@@ -94,6 +94,8 @@ files:
|
|
|
94
94
|
- ".gitignore"
|
|
95
95
|
- ".gitmodules"
|
|
96
96
|
- ".rspec"
|
|
97
|
+
- ".rubocop.yml"
|
|
98
|
+
- ".rubocop_todo.yml"
|
|
97
99
|
- Gemfile
|
|
98
100
|
- LICENSE.md
|
|
99
101
|
- Rakefile
|
|
@@ -104,13 +106,17 @@ files:
|
|
|
104
106
|
- docs/navigation.adoc
|
|
105
107
|
- lib/unitsml.rb
|
|
106
108
|
- lib/unitsml/dimension.rb
|
|
107
|
-
- lib/unitsml/
|
|
109
|
+
- lib/unitsml/errors.rb
|
|
110
|
+
- lib/unitsml/errors/base_error.rb
|
|
108
111
|
- lib/unitsml/errors/plurimath_load_error.rb
|
|
109
112
|
- lib/unitsml/extender.rb
|
|
110
113
|
- lib/unitsml/fenced.rb
|
|
114
|
+
- lib/unitsml/fenced_numeric.rb
|
|
111
115
|
- lib/unitsml/formula.rb
|
|
112
116
|
- lib/unitsml/intermediate_exp_rules.rb
|
|
117
|
+
- lib/unitsml/model.rb
|
|
113
118
|
- lib/unitsml/model/dimension.rb
|
|
119
|
+
- lib/unitsml/model/dimension_quantities.rb
|
|
114
120
|
- lib/unitsml/model/dimension_quantities/amount_of_substance.rb
|
|
115
121
|
- lib/unitsml/model/dimension_quantities/electric_current.rb
|
|
116
122
|
- lib/unitsml/model/dimension_quantities/length.rb
|
|
@@ -121,16 +127,21 @@ files:
|
|
|
121
127
|
- lib/unitsml/model/dimension_quantities/thermodynamic_temperature.rb
|
|
122
128
|
- lib/unitsml/model/dimension_quantities/time.rb
|
|
123
129
|
- lib/unitsml/model/prefix.rb
|
|
130
|
+
- lib/unitsml/model/prefixes.rb
|
|
124
131
|
- lib/unitsml/model/prefixes/name.rb
|
|
125
132
|
- lib/unitsml/model/prefixes/symbol.rb
|
|
133
|
+
- lib/unitsml/model/quantities.rb
|
|
126
134
|
- lib/unitsml/model/quantities/name.rb
|
|
127
135
|
- lib/unitsml/model/quantity.rb
|
|
128
136
|
- lib/unitsml/model/unit.rb
|
|
137
|
+
- lib/unitsml/model/units.rb
|
|
129
138
|
- lib/unitsml/model/units/enumerated_root_unit.rb
|
|
130
139
|
- lib/unitsml/model/units/name.rb
|
|
131
140
|
- lib/unitsml/model/units/root_units.rb
|
|
132
141
|
- lib/unitsml/model/units/symbol.rb
|
|
133
142
|
- lib/unitsml/model/units/system.rb
|
|
143
|
+
- lib/unitsml/namespace.rb
|
|
144
|
+
- lib/unitsml/number.rb
|
|
134
145
|
- lib/unitsml/parse.rb
|
|
135
146
|
- lib/unitsml/parser.rb
|
|
136
147
|
- lib/unitsml/prefix.rb
|
|
@@ -148,6 +159,7 @@ files:
|
|
|
148
159
|
- lib/unitsml/unitsdb/units.rb
|
|
149
160
|
- lib/unitsml/utility.rb
|
|
150
161
|
- lib/unitsml/version.rb
|
|
162
|
+
- unitsdb/Gemfile
|
|
151
163
|
- unitsdb/LICENSE.md
|
|
152
164
|
- unitsdb/README.adoc
|
|
153
165
|
- unitsdb/RELEASE-NOTES.adoc
|