unitsml 0.6.0 → 0.6.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.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/.rubocop_todo.yml +276 -279
- data/Gemfile +13 -13
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/lib/unitsml/dimension.rb +3 -3
- data/lib/unitsml/errors.rb +2 -2
- data/lib/unitsml/extender.rb +9 -9
- data/lib/unitsml/fenced.rb +3 -3
- data/lib/unitsml/formula.rb +29 -20
- data/lib/unitsml/intermediate_exp_rules.rb +30 -20
- data/lib/unitsml/model/dimension.rb +1 -1
- data/lib/unitsml/model/dimension_quantities.rb +8 -4
- data/lib/unitsml/model/prefix.rb +1 -1
- data/lib/unitsml/model/prefixes/name.rb +2 -2
- data/lib/unitsml/model/prefixes/symbol.rb +1 -1
- data/lib/unitsml/model/quantities/name.rb +2 -2
- data/lib/unitsml/model/quantity.rb +2 -2
- data/lib/unitsml/model/unit.rb +1 -1
- data/lib/unitsml/model/units/name.rb +2 -2
- data/lib/unitsml/model/units/root_units.rb +1 -1
- data/lib/unitsml/model/units/symbol.rb +4 -2
- data/lib/unitsml/model/units/system.rb +2 -2
- data/lib/unitsml/model/units.rb +5 -5
- data/lib/unitsml/namespace.rb +2 -2
- data/lib/unitsml/number.rb +11 -11
- data/lib/unitsml/parse.rb +30 -19
- data/lib/unitsml/parser.rb +11 -11
- data/lib/unitsml/prefix.rb +6 -4
- data/lib/unitsml/transform.rb +26 -26
- data/lib/unitsml/unit.rb +8 -6
- data/lib/unitsml/unitsdb/dimension.rb +6 -4
- data/lib/unitsml/unitsdb/dimensions.rb +4 -0
- data/lib/unitsml/unitsdb/unit.rb +2 -2
- data/lib/unitsml/unitsdb/units.rb +4 -0
- data/lib/unitsml/unitsdb.rb +8 -19
- data/lib/unitsml/utility.rb +81 -70
- data/lib/unitsml/version.rb +1 -1
- data/lib/unitsml.rb +31 -31
- data/unitsml.gemspec +22 -19
- metadata +5 -23
- data/unitsdb/Gemfile +0 -6
- data/unitsdb/LICENSE.md +0 -53
- data/unitsdb/README.adoc +0 -1253
- data/unitsdb/RELEASE-NOTES.adoc +0 -269
- data/unitsdb/dimensions.yaml +0 -1864
- data/unitsdb/prefixes.yaml +0 -874
- data/unitsdb/quantities.yaml +0 -3715
- data/unitsdb/scales.yaml +0 -97
- data/unitsdb/schemas/README.md +0 -159
- data/unitsdb/schemas/dimensions-schema.yaml +0 -153
- data/unitsdb/schemas/prefixes-schema.yaml +0 -155
- data/unitsdb/schemas/quantities-schema.yaml +0 -117
- data/unitsdb/schemas/scales-schema.yaml +0 -106
- data/unitsdb/schemas/unit_systems-schema.yaml +0 -116
- data/unitsdb/schemas/units-schema.yaml +0 -215
- data/unitsdb/spec/units_spec.rb +0 -22
- data/unitsdb/unit_systems.yaml +0 -78
- data/unitsdb/units.yaml +0 -14052
- data/unitsdb/validate_schemas.rb +0 -203
data/unitsdb/validate_schemas.rb
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "yaml"
|
|
4
|
-
require "json-schema"
|
|
5
|
-
require "json"
|
|
6
|
-
require "pathname"
|
|
7
|
-
|
|
8
|
-
class SchemaValidator
|
|
9
|
-
def initialize
|
|
10
|
-
@schemas_dir = Pathname.new("schemas")
|
|
11
|
-
@errors_found = false
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def validate_all
|
|
15
|
-
puts "UnitsDB Schema Validation"
|
|
16
|
-
puts "=" * 50
|
|
17
|
-
|
|
18
|
-
# Define the mapping of YAML files to their schemas
|
|
19
|
-
file_schema_map = {
|
|
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
|
-
}
|
|
27
|
-
|
|
28
|
-
file_schema_map.each do |yaml_file, schema_file|
|
|
29
|
-
validate_file(yaml_file, schema_file)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
puts "\n#{'=' * 50}"
|
|
33
|
-
if @errors_found
|
|
34
|
-
puts "❌ Validation completed with errors"
|
|
35
|
-
exit 1
|
|
36
|
-
else
|
|
37
|
-
puts "✅ All files passed validation"
|
|
38
|
-
exit 0
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
def validate_file(yaml_file, schema_file)
|
|
45
|
-
puts "\nValidating #{yaml_file}..."
|
|
46
|
-
|
|
47
|
-
# Check if files exist
|
|
48
|
-
unless File.exist?(yaml_file)
|
|
49
|
-
puts "❌ YAML file not found: #{yaml_file}"
|
|
50
|
-
@errors_found = true
|
|
51
|
-
return
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
schema_path = @schemas_dir / schema_file
|
|
55
|
-
unless File.exist?(schema_path)
|
|
56
|
-
puts "❌ Schema file not found: #{schema_path}"
|
|
57
|
-
@errors_found = true
|
|
58
|
-
return
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
begin
|
|
62
|
-
# Load YAML data
|
|
63
|
-
yaml_data = YAML.load_file(yaml_file)
|
|
64
|
-
|
|
65
|
-
# Load schema (YAML schemas need to be converted to JSON for json-schema gem)
|
|
66
|
-
schema_yaml = YAML.load_file(schema_path)
|
|
67
|
-
schema_json = JSON.parse(schema_yaml.to_json)
|
|
68
|
-
|
|
69
|
-
# Validate
|
|
70
|
-
errors = JSON::Validator.fully_validate(schema_json, yaml_data,
|
|
71
|
-
errors_as_objects: true,
|
|
72
|
-
validate_schema: true)
|
|
73
|
-
|
|
74
|
-
if errors.empty?
|
|
75
|
-
puts "✅ #{yaml_file} - Valid"
|
|
76
|
-
else
|
|
77
|
-
puts "❌ #{yaml_file} - #{errors.length} error(s) found:"
|
|
78
|
-
@errors_found = true
|
|
79
|
-
|
|
80
|
-
errors.each_with_index do |error, index|
|
|
81
|
-
puts "\n Error #{index + 1}:"
|
|
82
|
-
puts " Path: #{error[:fragment] || 'root'}"
|
|
83
|
-
puts " Message: #{error[:message]}"
|
|
84
|
-
|
|
85
|
-
# Try to provide more context about the location
|
|
86
|
-
if error[:fragment] && !error[:fragment].empty?
|
|
87
|
-
path_parts = error[:fragment].split("/")
|
|
88
|
-
puts " Location: #{describe_path(path_parts, yaml_data)}"
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
# Show the failing value if available
|
|
92
|
-
if error[:failed_attribute] && error[:failed_attribute] != "schema"
|
|
93
|
-
puts " Failed validation: #{error[:failed_attribute]}"
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
rescue YAML::SyntaxError => e
|
|
98
|
-
puts "❌ YAML syntax error in #{yaml_file}:"
|
|
99
|
-
puts " Line #{e.line}: #{e.problem}"
|
|
100
|
-
@errors_found = true
|
|
101
|
-
rescue JSON::Schema::ValidationError => e
|
|
102
|
-
puts "❌ Schema validation error: #{e.message}"
|
|
103
|
-
@errors_found = true
|
|
104
|
-
rescue StandardError => e
|
|
105
|
-
puts "❌ Unexpected error validating #{yaml_file}: #{e.message}"
|
|
106
|
-
puts " #{e.class}: #{e.backtrace.first}"
|
|
107
|
-
@errors_found = true
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
def describe_path(path_parts, data)
|
|
112
|
-
current = data
|
|
113
|
-
description_parts = []
|
|
114
|
-
|
|
115
|
-
path_parts.each do |part|
|
|
116
|
-
next if part.empty? || part == "#"
|
|
117
|
-
|
|
118
|
-
if /^\d+$/.match?(part)
|
|
119
|
-
# Array index
|
|
120
|
-
index = part.to_i
|
|
121
|
-
if current.is_a?(Array) && current[index]
|
|
122
|
-
description_parts << "item #{index}"
|
|
123
|
-
current = current[index]
|
|
124
|
-
else
|
|
125
|
-
description_parts << "index #{index} (out of bounds)"
|
|
126
|
-
break
|
|
127
|
-
end
|
|
128
|
-
elsif current.is_a?(Hash) && current.key?(part)
|
|
129
|
-
# Object property
|
|
130
|
-
description_parts << "property '#{part}'"
|
|
131
|
-
current = current[part]
|
|
132
|
-
else
|
|
133
|
-
description_parts << "missing property '#{part}'"
|
|
134
|
-
break
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
description_parts.join(" -> ")
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# Additional helper methods for detailed error reporting
|
|
143
|
-
class SchemaValidator
|
|
144
|
-
def self.check_dependencies
|
|
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
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def self.run_with_options
|
|
153
|
-
check_dependencies
|
|
154
|
-
|
|
155
|
-
if ARGV.include?("--help") || ARGV.include?("-h")
|
|
156
|
-
show_help
|
|
157
|
-
exit 0
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
validator = new
|
|
161
|
-
|
|
162
|
-
if ARGV.include?("--verbose") || ARGV.include?("-v")
|
|
163
|
-
puts "Ruby version: #{RUBY_VERSION}"
|
|
164
|
-
puts "JSON Schema gem version: #{JSON::Schema::VERSION}"
|
|
165
|
-
puts "Working directory: #{Dir.pwd}"
|
|
166
|
-
puts ""
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
validator.validate_all
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def self.show_help
|
|
173
|
-
puts <<~HELP
|
|
174
|
-
UnitsDB Schema Validator
|
|
175
|
-
|
|
176
|
-
Usage: ruby validate_schemas.rb [options]
|
|
177
|
-
|
|
178
|
-
Options:
|
|
179
|
-
-h, --help Show this help message
|
|
180
|
-
-v, --verbose Show additional information
|
|
181
|
-
|
|
182
|
-
This script validates all YAML files in the UnitsDB repository
|
|
183
|
-
against their corresponding JSON schemas in the schemas/ directory.
|
|
184
|
-
|
|
185
|
-
Files validated:
|
|
186
|
-
- units.yaml
|
|
187
|
-
- quantities.yaml
|
|
188
|
-
- scales.yaml
|
|
189
|
-
- prefixes.yaml
|
|
190
|
-
- unit_systems.yaml
|
|
191
|
-
- dimensions.yaml
|
|
192
|
-
|
|
193
|
-
Exit codes:
|
|
194
|
-
0 - All files passed validation
|
|
195
|
-
1 - Validation errors found or script error
|
|
196
|
-
HELP
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
# Run the validator if this script is executed directly
|
|
201
|
-
if __FILE__ == $0
|
|
202
|
-
SchemaValidator.run_with_options
|
|
203
|
-
end
|