unitsml 0.6.12 → 0.6.13

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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rake.yml +3 -0
  3. data/Gemfile +0 -1
  4. data/docs/README.adoc +221 -1
  5. data/lib/unitsml/compose/builder.rb +347 -0
  6. data/lib/unitsml/compose/composable.rb +118 -0
  7. data/lib/unitsml/compose/composite.rb +145 -0
  8. data/lib/unitsml/compose/term_tree.rb +48 -0
  9. data/lib/unitsml/compose.rb +151 -0
  10. data/lib/unitsml/conversion/definition.rb +117 -0
  11. data/lib/unitsml/conversion.rb +97 -41
  12. data/lib/unitsml/dimension.rb +30 -3
  13. data/lib/unitsml/errors/base_error.rb +11 -0
  14. data/lib/unitsml/errors/empty_composition_error.rb +14 -0
  15. data/lib/unitsml/errors/invalid_power_error.rb +37 -0
  16. data/lib/unitsml/errors/invalid_unit_entry_error.rb +44 -0
  17. data/lib/unitsml/errors/misplaced_extender_error.rb +18 -0
  18. data/lib/unitsml/errors/mixed_terms_error.rb +15 -0
  19. data/lib/unitsml/errors/parse_error.rb +18 -0
  20. data/lib/unitsml/errors/unknown_dimension_error.rb +18 -0
  21. data/lib/unitsml/errors/unknown_prefix_error.rb +15 -0
  22. data/lib/unitsml/errors/unknown_unit_error.rb +16 -0
  23. data/lib/unitsml/errors.rb +11 -0
  24. data/lib/unitsml/formula.rb +65 -4
  25. data/lib/unitsml/model/unit.rb +2 -0
  26. data/lib/unitsml/model/units/conversion_note.rb +19 -0
  27. data/lib/unitsml/model/units/conversions.rb +25 -0
  28. data/lib/unitsml/model/units/float64_conversion_from.rb +62 -0
  29. data/lib/unitsml/model/units/special_conversion_from.rb +27 -0
  30. data/lib/unitsml/model/units/wsdl_conversion_from.rb +26 -0
  31. data/lib/unitsml/model/units.rb +5 -0
  32. data/lib/unitsml/number.rb +5 -1
  33. data/lib/unitsml/opal/database_payload.rb +1 -1
  34. data/lib/unitsml/opal.rb +22 -0
  35. data/lib/unitsml/parser.rb +12 -1
  36. data/lib/unitsml/power_numerator.rb +61 -0
  37. data/lib/unitsml/quantity.rb +95 -23
  38. data/lib/unitsml/unit.rb +60 -4
  39. data/lib/unitsml/unitsdb/quantities.rb +21 -0
  40. data/lib/unitsml/unitsdb/units.rb +6 -0
  41. data/lib/unitsml/utility.rb +61 -10
  42. data/lib/unitsml/version.rb +1 -1
  43. data/lib/unitsml.rb +10 -0
  44. metadata +23 -2
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ # Descriptive note attached to a conversion definition (NoteType).
7
+ class ConversionNote < Lutaml::Model::Serializable
8
+ attribute :content, :string
9
+
10
+ xml do
11
+ element "ConversionNote"
12
+ namespace ::Unitsml::Namespace
13
+
14
+ map_content to: :content
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ # The Conversions container of a unit: linear definitions
7
+ # (Float64ConversionFrom) and the non-linear / remote stand-ins
8
+ # (SpecialConversionFrom, WSDLConversionFrom).
9
+ class Conversions < Lutaml::Model::Serializable
10
+ attribute :float64_conversion_from, Float64ConversionFrom
11
+ attribute :special_conversion_from, SpecialConversionFrom
12
+ attribute :wsdl_conversion_from, WsdlConversionFrom
13
+
14
+ xml do
15
+ element "Conversions"
16
+ namespace ::Unitsml::Namespace
17
+
18
+ map_element :Float64ConversionFrom, to: :float64_conversion_from
19
+ map_element :SpecialConversionFrom, to: :special_conversion_from
20
+ map_element :WSDLConversionFrom, to: :wsdl_conversion_from
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ # The linear conversion definition of UnitsML 1.0 (Float64ConversionFrom):
7
+ # y = d + ((b / c) (x + a)) from the initial unit x to this unit y.
8
+ #
9
+ # Decimal attributes are lexical strings, preserved verbatim per the
10
+ # numeric contract (CalConnect 36813): "273.15" never becomes 273.15.
11
+ # The XSD defaults (a=0, b=1, c=1, d=0) apply where an attribute is
12
+ # absent; the conversion engine resolves them at application time.
13
+ class Float64ConversionFrom < Lutaml::Model::Serializable
14
+ XSD_DEFAULTS = {
15
+ initial_addend: "0",
16
+ multiplicand: "1",
17
+ divisor: "1",
18
+ final_addend: "0",
19
+ }.freeze
20
+
21
+ attribute :id, :xml_id
22
+ attribute :initial_unit, :string
23
+ attribute :initial_addend, :string
24
+ attribute :initial_addend_decimal_place, :integer
25
+ attribute :multiplicand, :string
26
+ attribute :multiplicand_digits, :integer
27
+ attribute :divisor, :string
28
+ attribute :divisor_digits, :integer
29
+ attribute :final_addend, :string
30
+ attribute :final_addend_decimal_place, :integer
31
+ attribute :exact, :boolean
32
+ attribute :conversion_note, ConversionNote, collection: true
33
+
34
+ xml do
35
+ element "Float64ConversionFrom"
36
+ namespace ::Unitsml::Namespace
37
+
38
+ map_attribute :id, to: :id
39
+ map_attribute :initialUnit, to: :initial_unit
40
+ map_attribute :initialAddend, to: :initial_addend
41
+ map_attribute :initialAddendDecimalPlace,
42
+ to: :initial_addend_decimal_place
43
+ map_attribute :multiplicand, to: :multiplicand
44
+ map_attribute :multiplicandDigits, to: :multiplicand_digits
45
+ map_attribute :divisor, to: :divisor
46
+ map_attribute :divisorDigits, to: :divisor_digits
47
+ map_attribute :finalAddend, to: :final_addend
48
+ map_attribute :finalAddendDecimalPlace,
49
+ to: :final_addend_decimal_place
50
+ map_attribute :exact, to: :exact
51
+ map_element :ConversionNote, to: :conversion_note
52
+ end
53
+
54
+ # Lexical attribute with the XSD default applied.
55
+ def lexical_decimal(name)
56
+ value = public_send(name)
57
+ value.nil? ? XSD_DEFAULTS.fetch(name) : value
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ # A conversion more complex than the linear equation
7
+ # (SpecialConversionFrom). Never approximated by a linear factor;
8
+ # the conversion engine refuses it with a typed error.
9
+ class SpecialConversionFrom < Lutaml::Model::Serializable
10
+ attribute :id, :xml_id
11
+ attribute :initial_unit, :string
12
+ attribute :conversion_url, :string
13
+ attribute :conversion_description, :string, collection: true
14
+
15
+ xml do
16
+ element "SpecialConversionFrom"
17
+ namespace ::Unitsml::Namespace
18
+
19
+ map_attribute :id, to: :id
20
+ map_attribute :initialUnit, to: :initial_unit
21
+ map_attribute :conversionURL, to: :conversion_url
22
+ map_element :ConversionDescription, to: :conversion_description
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ # A SOAP/WSDL-based conversion (WSDLConversionFrom). Remote by
7
+ # definition; the conversion engine refuses it with a typed error.
8
+ class WsdlConversionFrom < Lutaml::Model::Serializable
9
+ attribute :id, :xml_id
10
+ attribute :initial_unit, :string
11
+ attribute :wsdl_url, :string
12
+ attribute :wsdl_description, :string, collection: true
13
+
14
+ xml do
15
+ element "WSDLConversionFrom"
16
+ namespace ::Unitsml::Namespace
17
+
18
+ map_attribute :id, to: :id
19
+ map_attribute :initialUnit, to: :initial_unit
20
+ map_attribute :wsdlURL, to: :wsdl_url
21
+ map_element :WSDLDescription, to: :wsdl_description
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,11 +3,16 @@
3
3
  module Unitsml
4
4
  module Model
5
5
  module Units
6
+ autoload :ConversionNote, "unitsml/model/units/conversion_note"
7
+ autoload :Conversions, "unitsml/model/units/conversions"
6
8
  autoload :EnumeratedRootUnit, "unitsml/model/units/enumerated_root_unit"
9
+ autoload :Float64ConversionFrom, "unitsml/model/units/float64_conversion_from"
7
10
  autoload :Name, "unitsml/model/units/name"
8
11
  autoload :RootUnits, "unitsml/model/units/root_units"
9
12
  autoload :Symbol, "unitsml/model/units/symbol"
13
+ autoload :SpecialConversionFrom, "unitsml/model/units/special_conversion_from"
10
14
  autoload :System, "unitsml/model/units/system"
15
+ autoload :WsdlConversionFrom, "unitsml/model/units/wsdl_conversion_from"
11
16
  end
12
17
  end
13
18
  end
@@ -9,7 +9,11 @@ module Unitsml
9
9
  alias raw_value value
10
10
 
11
11
  def initialize(value)
12
- @value = value
12
+ # Number always holds a String representation; the render/compare helpers
13
+ # (to_html, negative?, update_negative_sign, ...) assume String, so a
14
+ # numeric value (e.g. a Float exponent from unit decomposition) is
15
+ # normalized here rather than crashing later.
16
+ @value = value.to_s
13
17
  end
14
18
 
15
19
  def ==(other)