unitsml 0.5.1 → 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.
Files changed (75) 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/.gitmodules +0 -3
  5. data/.rubocop.yml +18 -0
  6. data/.rubocop_todo.yml +495 -0
  7. data/Gemfile +8 -3
  8. data/Rakefile +3 -1
  9. data/bin/console +1 -0
  10. data/docs/README.adoc +2 -2
  11. data/lib/unitsml/dimension.rb +48 -34
  12. data/lib/unitsml/errors/base_error.rb +8 -0
  13. data/lib/unitsml/errors/plurimath_load_error.rb +1 -1
  14. data/lib/unitsml/errors.rb +8 -0
  15. data/lib/unitsml/extender.rb +16 -11
  16. data/lib/unitsml/fenced.rb +28 -8
  17. data/lib/unitsml/fenced_numeric.rb +13 -0
  18. data/lib/unitsml/formula.rb +35 -26
  19. data/lib/unitsml/intermediate_exp_rules.rb +68 -17
  20. data/lib/unitsml/model/dimension.rb +4 -14
  21. data/lib/unitsml/model/dimension_quantities/quantity.rb +2 -0
  22. data/lib/unitsml/model/dimension_quantities.rb +21 -0
  23. data/lib/unitsml/model/prefix.rb +4 -8
  24. data/lib/unitsml/model/prefixes/name.rb +5 -4
  25. data/lib/unitsml/model/prefixes/symbol.rb +3 -2
  26. data/lib/unitsml/model/prefixes.rb +10 -0
  27. data/lib/unitsml/model/quantities/name.rb +4 -3
  28. data/lib/unitsml/model/quantities.rb +9 -0
  29. data/lib/unitsml/model/quantity.rb +4 -6
  30. data/lib/unitsml/model/unit.rb +4 -9
  31. data/lib/unitsml/model/units/enumerated_root_unit.rb +1 -0
  32. data/lib/unitsml/model/units/name.rb +4 -3
  33. data/lib/unitsml/model/units/root_units.rb +3 -2
  34. data/lib/unitsml/model/units/symbol.rb +5 -2
  35. data/lib/unitsml/model/units/system.rb +4 -3
  36. data/lib/unitsml/model/units.rb +13 -0
  37. data/lib/unitsml/model.rb +15 -0
  38. data/lib/unitsml/namespace.rb +8 -0
  39. data/lib/unitsml/number.rb +79 -0
  40. data/lib/unitsml/parse.rb +31 -19
  41. data/lib/unitsml/parser.rb +5 -6
  42. data/lib/unitsml/prefix.rb +11 -9
  43. data/lib/unitsml/sqrt.rb +3 -3
  44. data/lib/unitsml/transform.rb +117 -55
  45. data/lib/unitsml/unit.rb +43 -33
  46. data/lib/unitsml/unitsdb/dimension.rb +5 -3
  47. data/lib/unitsml/unitsdb/dimensions.rb +6 -4
  48. data/lib/unitsml/unitsdb/prefixes.rb +0 -2
  49. data/lib/unitsml/unitsdb/quantities.rb +0 -2
  50. data/lib/unitsml/unitsdb/units.rb +6 -4
  51. data/lib/unitsml/unitsdb.rb +17 -23
  52. data/lib/unitsml/utility.rb +91 -42
  53. data/lib/unitsml/version.rb +3 -1
  54. data/lib/unitsml.rb +56 -38
  55. data/unitsml.gemspec +24 -19
  56. metadata +29 -35
  57. data/lib/unitsml/error.rb +0 -8
  58. data/unitsdb/LICENSE.md +0 -53
  59. data/unitsdb/README.adoc +0 -1071
  60. data/unitsdb/RELEASE-NOTES.adoc +0 -269
  61. data/unitsdb/dimensions.yaml +0 -1512
  62. data/unitsdb/prefixes.yaml +0 -774
  63. data/unitsdb/quantities.yaml +0 -3113
  64. data/unitsdb/scales.yaml +0 -97
  65. data/unitsdb/schemas/README.md +0 -159
  66. data/unitsdb/schemas/dimensions-schema.yaml +0 -157
  67. data/unitsdb/schemas/prefixes-schema.yaml +0 -159
  68. data/unitsdb/schemas/quantities-schema.yaml +0 -120
  69. data/unitsdb/schemas/scales-schema.yaml +0 -109
  70. data/unitsdb/schemas/unit_systems-schema.yaml +0 -120
  71. data/unitsdb/schemas/units-schema.yaml +0 -219
  72. data/unitsdb/spec/units_spec.rb +0 -20
  73. data/unitsdb/unit_systems.yaml +0 -74
  74. data/unitsdb/units.yaml +0 -13101
  75. data/unitsdb/validate_schemas.rb +0 -208
@@ -1,208 +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
-
98
- rescue YAML::SyntaxError => e
99
- puts "❌ YAML syntax error in #{yaml_file}:"
100
- puts " Line #{e.line}: #{e.problem}"
101
- @errors_found = true
102
- rescue JSON::Schema::ValidationError => e
103
- puts "❌ Schema validation error: #{e.message}"
104
- @errors_found = true
105
- rescue StandardError => e
106
- puts "❌ Unexpected error validating #{yaml_file}: #{e.message}"
107
- puts " #{e.class}: #{e.backtrace.first}"
108
- @errors_found = true
109
- end
110
- end
111
-
112
- def describe_path(path_parts, data)
113
- current = data
114
- description_parts = []
115
-
116
- path_parts.each do |part|
117
- next if part.empty? || part == '#'
118
-
119
- if part =~ /^\d+$/
120
- # Array index
121
- index = part.to_i
122
- if current.is_a?(Array) && current[index]
123
- description_parts << "item #{index}"
124
- current = current[index]
125
- else
126
- description_parts << "index #{index} (out of bounds)"
127
- break
128
- end
129
- else
130
- # Object property
131
- if current.is_a?(Hash) && current.key?(part)
132
- description_parts << "property '#{part}'"
133
- current = current[part]
134
- else
135
- description_parts << "missing property '#{part}'"
136
- break
137
- end
138
- end
139
- end
140
-
141
- description_parts.join(' -> ')
142
- end
143
- end
144
-
145
- # Additional helper methods for detailed error reporting
146
- class SchemaValidator
147
- def self.check_dependencies
148
- begin
149
- require 'json-schema'
150
- rescue LoadError
151
- puts "❌ Missing required gem: json-schema"
152
- puts " Install with: gem install json-schema"
153
- exit 1
154
- end
155
- end
156
-
157
- def self.run_with_options
158
- check_dependencies
159
-
160
- if ARGV.include?('--help') || ARGV.include?('-h')
161
- show_help
162
- exit 0
163
- end
164
-
165
- validator = new
166
-
167
- if ARGV.include?('--verbose') || ARGV.include?('-v')
168
- puts "Ruby version: #{RUBY_VERSION}"
169
- puts "JSON Schema gem version: #{JSON::Schema::VERSION}"
170
- puts "Working directory: #{Dir.pwd}"
171
- puts ""
172
- end
173
-
174
- validator.validate_all
175
- end
176
-
177
- def self.show_help
178
- puts <<~HELP
179
- UnitsDB Schema Validator
180
-
181
- Usage: ruby validate_schemas.rb [options]
182
-
183
- Options:
184
- -h, --help Show this help message
185
- -v, --verbose Show additional information
186
-
187
- This script validates all YAML files in the UnitsDB repository
188
- against their corresponding JSON schemas in the schemas/ directory.
189
-
190
- Files validated:
191
- - units.yaml
192
- - quantities.yaml
193
- - scales.yaml
194
- - prefixes.yaml
195
- - unit_systems.yaml
196
- - dimensions.yaml
197
-
198
- Exit codes:
199
- 0 - All files passed validation
200
- 1 - Validation errors found or script error
201
- HELP
202
- end
203
- end
204
-
205
- # Run the validator if this script is executed directly
206
- if __FILE__ == $0
207
- SchemaValidator.run_with_options
208
- end