UnitsDB v2 support - #47
Conversation
adb67f9 to
b7b19bd
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR updates the library to be compatible with UnitsDB v2.0 by bumping the dependency, switching over to the new UnitsDB v2 APIs, and adjusting XML output to reflect updated identifiers and structures.
- Bumped
unitsdbdependency in the gemspec and updated the Git submodule. - Refactored all
Unitsdbmodel integrations (Units, Unit, Prefixes, Dimensions, etc.) to use v2 methods and registered them with the global register. - Updated XML generation logic and tests to expect the new v2 identifiers and element structures.
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| unitsml.gemspec | Bump unitsdb dependency from ~>1.0 to ~>2.0 |
| unitsdb | Updated submodule commit to v2 |
| spec/unitsml/conv/xml_spec.rb | Updated expected XML in tests for new unit and dimension IDs |
| lib/unitsml/utility.rb | Adjusted dimension and unit‐ID generation for v2 API |
| lib/unitsml/unitsdb/units.rb | Refactored Units finder methods for v2 |
| lib/unitsml/unitsdb/unit.rb | Added dimension_url, en_name, nist_id for Unit class |
| lib/unitsml/unitsdb/quantities.rb | Adapted Quantities lookup to use new identifiers |
| lib/unitsml/unitsdb/prefixes.rb | Updated Prefixes to v2 symbol and identifier APIs |
| lib/unitsml/unitsdb/prefix_reference.rb | New class for v2 prefix references |
| lib/unitsml/unitsdb/dimensions.rb | Updated Dimensions lookup by vector |
| lib/unitsml/unitsdb/dimension_quantity.rb | Adapted dimension details symbol mapping |
| lib/unitsml/unitsdb/dimension.rb | Overrode Dimension for v2, including id and vector |
| lib/unitsml/unitsdb.rb | Switched YAML loaders to use registered v2 classes |
| lib/unitsml/unit.rb | Revised Unit class to use new v2 attributes and helpers |
| lib/unitsml/prefix.rb | Updated prefix handling to match v2 symbol APIs |
| lib/unitsml/parser.rb | Extracted unit expression parsing into helper |
| lib/unitsml/formula.rb | Changed normalization to use xml_postprocess_name |
| lib/unitsml/dimension.rb | Adjusted symbol lookup to match v2 API |
| lib/unitsml.rb | Registered global type substitutions for v2 classes |
| Gemfile | Added lutaml-model dependency from GitHub |
| <Time symbol="T" powerNumerator="-1"/> | ||
| </Dimension> | ||
|
|
||
| <Quantity xmlns="https://schema.unitsml.org/unitsml/1.0" xml:id="NISTq45" quantityType="base" dimensionURL="#NISTd24"> |
There was a problem hiding this comment.
The Quantity element still references the old dimensionURL "#NISTd24" despite updating the to use id "NISTd101". Update the dimensionURL to "#NISTd101" so the test matches the new identifier.
| <Quantity xmlns="https://schema.unitsml.org/unitsml/1.0" xml:id="NISTq45" quantityType="base" dimensionURL="#NISTd24"> | |
| <Quantity xmlns="https://schema.unitsml.org/unitsml/1.0" xml:id="NISTq45" quantityType="base" dimensionURL="#NISTd101"> |
|
|
||
| def register | ||
| @register ||= Lutaml::Model::GlobalRegister.lookup( | ||
| Lutaml::Model::Config.default_register, |
There was a problem hiding this comment.
I'm a bit confused. Is the UnitsML gem going to have its own model register? Is it sharing a model register with something else?
There was a problem hiding this comment.
@ronaldtse, good catch‒the current code uses the default register, which can be shared. I believe it would be more appropriate to create a dedicated register named unitsml-ruby. I'll update the code.
Please let me know if you have any suggestions.
|
Thank you @suleman-uzair ! |
This PR updates the conversion methods to support the latest version of UnitsDB v2.0.
closes #44