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.
Files changed (72) 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/.rubocop.yml +18 -0
  5. data/.rubocop_todo.yml +498 -0
  6. data/Gemfile +16 -11
  7. data/Rakefile +5 -3
  8. data/bin/console +4 -3
  9. data/docs/README.adoc +2 -2
  10. data/lib/unitsml/dimension.rb +49 -35
  11. data/lib/unitsml/errors/base_error.rb +8 -0
  12. data/lib/unitsml/errors/plurimath_load_error.rb +1 -1
  13. data/lib/unitsml/errors.rb +8 -0
  14. data/lib/unitsml/extender.rb +21 -16
  15. data/lib/unitsml/fenced.rb +30 -10
  16. data/lib/unitsml/fenced_numeric.rb +13 -0
  17. data/lib/unitsml/formula.rb +29 -29
  18. data/lib/unitsml/intermediate_exp_rules.rb +58 -17
  19. data/lib/unitsml/model/dimension.rb +4 -14
  20. data/lib/unitsml/model/dimension_quantities/quantity.rb +2 -0
  21. data/lib/unitsml/model/dimension_quantities.rb +17 -0
  22. data/lib/unitsml/model/prefix.rb +4 -8
  23. data/lib/unitsml/model/prefixes/name.rb +5 -4
  24. data/lib/unitsml/model/prefixes/symbol.rb +3 -2
  25. data/lib/unitsml/model/prefixes.rb +10 -0
  26. data/lib/unitsml/model/quantities/name.rb +4 -3
  27. data/lib/unitsml/model/quantities.rb +9 -0
  28. data/lib/unitsml/model/quantity.rb +5 -7
  29. data/lib/unitsml/model/unit.rb +4 -9
  30. data/lib/unitsml/model/units/enumerated_root_unit.rb +1 -0
  31. data/lib/unitsml/model/units/name.rb +4 -3
  32. data/lib/unitsml/model/units/root_units.rb +3 -2
  33. data/lib/unitsml/model/units/symbol.rb +2 -1
  34. data/lib/unitsml/model/units/system.rb +4 -3
  35. data/lib/unitsml/model/units.rb +13 -0
  36. data/lib/unitsml/model.rb +15 -0
  37. data/lib/unitsml/namespace.rb +8 -0
  38. data/lib/unitsml/number.rb +79 -0
  39. data/lib/unitsml/parse.rb +20 -19
  40. data/lib/unitsml/parser.rb +13 -14
  41. data/lib/unitsml/prefix.rb +10 -10
  42. data/lib/unitsml/sqrt.rb +3 -3
  43. data/lib/unitsml/transform.rb +133 -71
  44. data/lib/unitsml/unit.rb +41 -33
  45. data/lib/unitsml/unitsdb/dimension.rb +3 -3
  46. data/lib/unitsml/unitsdb/dimensions.rb +2 -4
  47. data/lib/unitsml/unitsdb/prefixes.rb +0 -2
  48. data/lib/unitsml/unitsdb/quantities.rb +0 -2
  49. data/lib/unitsml/unitsdb/unit.rb +2 -2
  50. data/lib/unitsml/unitsdb/units.rb +2 -4
  51. data/lib/unitsml/unitsdb.rb +14 -9
  52. data/lib/unitsml/utility.rb +111 -73
  53. data/lib/unitsml/version.rb +3 -1
  54. data/lib/unitsml.rb +51 -33
  55. data/unitsdb/Gemfile +6 -0
  56. data/unitsdb/README.adoc +193 -11
  57. data/unitsdb/dimensions.yaml +360 -8
  58. data/unitsdb/prefixes.yaml +104 -4
  59. data/unitsdb/quantities.yaml +602 -0
  60. data/unitsdb/schemas/dimensions-schema.yaml +2 -6
  61. data/unitsdb/schemas/prefixes-schema.yaml +2 -6
  62. data/unitsdb/schemas/quantities-schema.yaml +2 -5
  63. data/unitsdb/schemas/scales-schema.yaml +2 -5
  64. data/unitsdb/schemas/unit_systems-schema.yaml +2 -6
  65. data/unitsdb/schemas/units-schema.yaml +2 -6
  66. data/unitsdb/spec/units_spec.rb +3 -1
  67. data/unitsdb/unit_systems.yaml +4 -0
  68. data/unitsdb/units.yaml +957 -6
  69. data/unitsdb/validate_schemas.rb +32 -37
  70. data/unitsml.gemspec +3 -1
  71. metadata +29 -17
  72. data/lib/unitsml/error.rb +0 -8
@@ -2,15 +2,16 @@
2
2
 
3
3
  module Unitsml
4
4
  module Model
5
- class Prefixes
5
+ module Prefixes
6
6
  class Name < Lutaml::Model::Serializable
7
- attribute :lang, :string, default: -> { "en" }
7
+ attribute :lang, :xml_lang, default: -> { 'en' }
8
8
  attribute :content, :string
9
9
 
10
10
  xml do
11
- root "PrefixName"
11
+ element 'PrefixName'
12
+ namespace ::Unitsml::Namespace
12
13
 
13
- map_attribute :lang, to: :lang, namespace: nil, prefix: "xml", render_default: true
14
+ map_attribute :lang, to: :lang, render_default: true
14
15
  map_content to: :content
15
16
  end
16
17
  end
@@ -2,13 +2,14 @@
2
2
 
3
3
  module Unitsml
4
4
  module Model
5
- class Prefixes
5
+ module Prefixes
6
6
  class Symbol < Lutaml::Model::Serializable
7
7
  attribute :type, :string
8
8
  attribute :content, :string
9
9
 
10
10
  xml do
11
- root "PrefixSymbol"
11
+ element 'PrefixSymbol'
12
+ namespace ::Unitsml::Namespace
12
13
 
13
14
  map_attribute :type, to: :type
14
15
  map_content to: :content
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Prefixes
6
+ autoload :Name, "#{__dir__}/prefixes/name"
7
+ autoload :Symbol, "#{__dir__}/prefixes/symbol"
8
+ end
9
+ end
10
+ end
@@ -4,13 +4,14 @@ module Unitsml
4
4
  module Model
5
5
  module Quantities
6
6
  class Name < Lutaml::Model::Serializable
7
- attribute :lang, :string, default: -> { "en-US" }
7
+ attribute :lang, :xml_lang, default: -> { 'en' }
8
8
  attribute :content, :string
9
9
 
10
10
  xml do
11
- root "QuantityName"
11
+ element 'QuantityName'
12
+ namespace ::Unitsml::Namespace
12
13
 
13
- map_attribute :lang, to: :lang, namespace: nil, prefix: "xml", render_default: true
14
+ map_attribute :lang, to: :lang, render_default: true
14
15
  map_content to: :content
15
16
  end
16
17
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Quantities
6
+ autoload :Name, "#{__dir__}/quantities/name"
7
+ end
8
+ end
9
+ end
@@ -1,20 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "unitsml/model/quantities/name"
4
-
5
3
  module Unitsml
6
4
  module Model
7
5
  class Quantity < Lutaml::Model::Serializable
8
- attribute :id, :string
6
+ attribute :id, :xml_id
9
7
  attribute :name, Quantities::Name, collection: true
10
- attribute :quantity_type, :string, default: -> { "base" }
8
+ attribute :quantity_type, :string, default: -> { 'base' }
11
9
  attribute :dimension_url, :string
12
10
 
13
11
  xml do
14
- root "Quantity"
15
- namespace Unitsml::UNITSML_NS
12
+ namespace ::Unitsml::Namespace
13
+ element 'Quantity'
16
14
 
17
- map_attribute :id, to: :id, namespace: nil, prefix: "xml"
15
+ map_attribute :id, to: :id
18
16
  map_attribute :quantityType, to: :quantity_type, render_default: true
19
17
  map_attribute :dimensionURL, to: :dimension_url
20
18
  map_element :QuantityName, to: :name
@@ -1,14 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "unitsml/model/units/name"
4
- require "unitsml/model/units/symbol"
5
- require "unitsml/model/units/system"
6
- require "unitsml/model/units/root_units"
7
-
8
3
  module Unitsml
9
4
  module Model
10
5
  class Unit < Lutaml::Model::Serializable
11
- attribute :id, :string
6
+ attribute :id, :xml_id
12
7
  attribute :name, Units::Name
13
8
  attribute :dimension_url, :string
14
9
  attribute :symbol, Units::Symbol, collection: true
@@ -16,11 +11,11 @@ module Unitsml
16
11
  attribute :root_units, Units::RootUnits
17
12
 
18
13
  xml do
19
- root "Unit"
20
- namespace Unitsml::UNITSML_NS
14
+ namespace ::Unitsml::Namespace
15
+ element 'Unit'
21
16
 
22
17
  map_attribute :dimensionURL, to: :dimension_url
23
- map_attribute :id, to: :id, namespace: nil, prefix: "xml"
18
+ map_attribute :id, to: :id
24
19
  map_element :UnitSystem, to: :system
25
20
  map_element :UnitName, to: :name
26
21
  map_element :UnitSymbol, to: :symbol
@@ -9,6 +9,7 @@ module Unitsml
9
9
  attribute :power_numerator, :string
10
10
 
11
11
  xml do
12
+ namespace ::Unitsml::Namespace
12
13
  map_attribute :unit, to: :unit
13
14
  map_attribute :prefix, to: :prefix
14
15
  map_attribute :powerNumerator, to: :power_numerator
@@ -5,13 +5,14 @@ module Unitsml
5
5
  module Units
6
6
  class Name < Lutaml::Model::Serializable
7
7
  attribute :name, :string
8
- attribute :lang, :string, default: -> { "en" }
8
+ attribute :lang, :xml_lang, default: -> { 'en' }
9
9
 
10
10
  xml do
11
- root "UnitName"
11
+ element 'UnitName'
12
+ namespace ::Unitsml::Namespace
12
13
 
13
14
  map_content to: :name
14
- map_attribute :lang, to: :lang, namespace: nil, prefix: "xml", render_default: true
15
+ map_attribute :lang, to: :lang, render_default: true
15
16
  end
16
17
  end
17
18
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "unitsml/model/units/enumerated_root_unit"
4
-
5
3
  module Unitsml
6
4
  module Model
7
5
  module Units
@@ -9,6 +7,9 @@ module Unitsml
9
7
  attribute :enumerated_root_unit, EnumeratedRootUnit, collection: true
10
8
 
11
9
  xml do
10
+ element 'RootUnits'
11
+ namespace ::Unitsml::Namespace
12
+
12
13
  map_element :EnumeratedRootUnit, to: :enumerated_root_unit
13
14
  end
14
15
  end
@@ -8,7 +8,8 @@ module Unitsml
8
8
  attribute :content, :string
9
9
 
10
10
  xml do
11
- root "UnitSymbol"
11
+ element 'UnitSymbol'
12
+ namespace ::Unitsml::Namespace
12
13
 
13
14
  map_attribute :type, to: :type
14
15
  map_content to: :content, with: { from: :content_from_xml, to: :content_to_xml }
@@ -6,14 +6,15 @@ module Unitsml
6
6
  class System < Lutaml::Model::Serializable
7
7
  attribute :name, :string
8
8
  attribute :type, :string
9
- attribute :lang, :string, default: -> { "en-US" }
9
+ attribute :lang, :xml_lang, default: -> { 'en' }
10
10
 
11
11
  xml do
12
- root "UnitSystem"
12
+ element 'UnitSystem'
13
+ namespace ::Unitsml::Namespace
13
14
 
14
15
  map_attribute :name, to: :name
15
16
  map_attribute :type, to: :type
16
- map_attribute :lang, to: :lang, namespace: nil, prefix: "xml", render_default: true
17
+ map_attribute :lang, to: :lang, render_default: true
17
18
  end
18
19
  end
19
20
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ autoload :EnumeratedRootUnit, 'unitsml/model/units/enumerated_root_unit'
7
+ autoload :Name, 'unitsml/model/units/name'
8
+ autoload :RootUnits, 'unitsml/model/units/root_units'
9
+ autoload :Symbol, 'unitsml/model/units/symbol'
10
+ autoload :System, 'unitsml/model/units/system'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ autoload :Dimension, "#{__dir__}/model/dimension"
6
+ autoload :DimensionQuantities, "#{__dir__}/model/dimension_quantities"
7
+ autoload :Namespace, "#{__dir__}/model/namespace"
8
+ autoload :Prefix, "#{__dir__}/model/prefix"
9
+ autoload :Prefixes, "#{__dir__}/model/prefixes"
10
+ autoload :Quantities, "#{__dir__}/model/quantities"
11
+ autoload :Quantity, "#{__dir__}/model/quantity"
12
+ autoload :Unit, "#{__dir__}/model/unit"
13
+ autoload :Units, "#{__dir__}/model/units"
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ class Namespace < Lutaml::Xml::Namespace
5
+ uri 'https://schema.unitsml.org/unitsml/1.0'
6
+ prefix_default 'unitsml'
7
+ end
8
+ end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ class Number
5
+ include FencedNumeric
6
+
7
+ attr_accessor :value
8
+ alias raw_value value
9
+
10
+ def initialize(value)
11
+ @value = value
12
+ end
13
+
14
+ def ==(other)
15
+ self.class == other.class &&
16
+ value == other&.value
17
+ end
18
+
19
+ def to_mathml(_options)
20
+ matched_value = value&.match(/-?(.+)/)
21
+ mn_value = matched_value ? matched_value[1] : value
22
+ mn_tag = ::Mml::V4::Mn.new(value: mn_value)
23
+ value.start_with?('-') ? mrow_hash(mn_tag) : mn_hash(mn_tag)
24
+ end
25
+
26
+ def to_html(_options)
27
+ value.sub('-', '&#x2212;')
28
+ end
29
+
30
+ def to_latex(_options)
31
+ value
32
+ end
33
+
34
+ def to_asciimath(_options)
35
+ value
36
+ end
37
+
38
+ def to_unicode(_options)
39
+ value
40
+ end
41
+
42
+ def negative?
43
+ value.start_with?('-')
44
+ end
45
+
46
+ def update_negative_sign
47
+ self.value = if negative?
48
+ value.delete_prefix('-')
49
+ else
50
+ ['-', value].join
51
+ end
52
+ end
53
+
54
+ def float_to_display
55
+ return '' if value.nil?
56
+
57
+ value.to_f.round(1).to_s.sub(/\.0$/, '')
58
+ end
59
+
60
+ private
61
+
62
+ def mrow_hash(mn_tag)
63
+ {
64
+ method_name: :mrow,
65
+ value: ::Mml::V4::Mrow.new(
66
+ mo_value: [::Mml::V4::Mo.new(value: '&#x2212;')],
67
+ mn_value: [mn_tag]
68
+ )
69
+ }
70
+ end
71
+
72
+ def mn_hash(mn_tag)
73
+ {
74
+ method_name: :mn,
75
+ value: mn_tag
76
+ }
77
+ end
78
+ end
79
+ end
data/lib/unitsml/parse.rb CHANGED
@@ -1,55 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "parslet"
4
- require "unitsml/unitsdb"
5
- require_relative "intermediate_exp_rules"
3
+ require 'parslet'
4
+
6
5
  module Unitsml
7
6
  class Parse < Parslet::Parser
8
7
  include IntermediateExpRules
9
8
 
10
- rule(:power) { str("^") >> slashed_number_int_exp }
11
- rule(:hyphen) { str("-") }
9
+ rule(:sqrt) { str('sqrt') }
10
+ rule(:power) { str('^') >> slashed_number_int_exp.as(:power_numerator) }
11
+ rule(:hyphen) { str('-') }
12
12
  rule(:number) { hyphen.maybe >> match(/[0-9]/).repeat(1) }
13
+ rule(:spaces) { match(/\s/).repeat(1) }
14
+ rule(:spaces?) { spaces.maybe }
13
15
 
14
- rule(:extender) { (forward_slashes | str("*")).as(:extender) }
16
+ rule(:extender) { (forward_slashes | str('*')).as(:extender) }
15
17
  rule(:sequence) { single_letter_prefixes >> units | double_letter_prefixes >> units | units }
16
18
 
19
+ rule(:opening_paren) { str('(') }
20
+ rule(:closing_paren) { str(')') }
17
21
  rule(:unit_and_power) { units >> power.maybe }
18
22
  rule(:slashed_number) { (number >> (forward_slashes >> number).maybe).as(:integer) }
19
- rule(:forward_slashes) { str("//") | str("/") }
23
+ rule(:forward_slashes) { str('//') | str('/') }
24
+ rule(:dimension_rules) { (sqrt_dimensions | powered_dimensions) >> extended_dimension_rules.maybe }
25
+ rule(:powered_dimensions) { dimensions >> power.maybe }
20
26
 
21
27
  rule(:units) do
22
- @@filtered_units ||= arr_to_expression(Unitsdb.units.filtered, "units")
28
+ @@filtered_units ||= arr_to_expression(::Unitsml::Unitsdb.units.filtered, 'unit')
23
29
  end
24
30
 
25
31
  rule(:single_letter_prefixes) do
26
- @@prefixes1 ||= arr_to_expression(Unitsdb.prefixes_by_size(1), "prefixes")
32
+ @@prefixes1 ||= arr_to_expression(::Unitsml::Unitsdb.prefixes_by_size(1), 'prefix')
27
33
  end
28
34
 
29
35
  rule(:double_letter_prefixes) do
30
- @@prefixes2 ||= arr_to_expression(Unitsdb.prefixes_by_size(2), "prefixes")
36
+ @@prefixes2 ||= arr_to_expression(::Unitsml::Unitsdb.prefixes_by_size(2), 'prefix')
31
37
  end
32
38
 
33
39
  rule(:dimensions) do
34
- @@dimensions ||= arr_to_expression(Unitsdb.dimensions.parsables.keys, "dimensions")
40
+ @@dimensions ||= arr_to_expression(::Unitsml::Unitsdb.dimensions.parsables.keys, 'dimension')
35
41
  end
36
42
 
37
43
  rule(:prefixes_units) do
38
44
  (sqrt_sequence >> extended_prefixed_units.maybe) |
39
- (str("1").as(:units) >> extended_prefixed_units.maybe) |
45
+ (str('1').as(:unit) >> extended_prefixed_units.maybe) |
40
46
  (unit_and_power >> extended_prefixed_units) |
41
- unit_and_power >> (str(")").present? | any.absent?) |
47
+ unit_and_power >> (any.absent? | (extender | opening_paren | closing_paren | spaces).present?) |
42
48
  (double_letter_prefixes >> unit_and_power >> extended_prefixed_units) |
43
49
  (double_letter_prefixes >> unit_and_power) |
44
50
  (single_letter_prefixes >> unit_and_power >> extended_prefixed_units) |
45
51
  (single_letter_prefixes >> unit_and_power)
46
52
  end
47
53
 
48
- rule(:dimension_rules) do
49
- (sqrt_dimensions >> extended_dimension_rules.maybe) |
50
- (powered_dimensions >> extended_dimension_rules.maybe)
51
- end
52
-
53
54
  rule(:expression) do
54
55
  prefixes_units_int_exp |
55
56
  dimension_rules_int_exp |
@@ -60,7 +61,7 @@ module Unitsml
60
61
  root :expression
61
62
 
62
63
  def arr_to_expression(arr, file_name)
63
- array = arr&.flatten&.compact&.sort_by(&:length).reverse
64
+ array = arr&.flatten&.compact&.sort_by(&:length)&.reverse
64
65
  array&.reduce do |expression, expr_string|
65
66
  expression = str(expression).as(file_name.to_sym) if expression.is_a?(String)
66
67
  expression | str(expr_string).as(file_name.to_sym)
@@ -5,10 +5,10 @@ module Unitsml
5
5
  attr_accessor :text
6
6
 
7
7
  def initialize(text)
8
- @regexp = %r{(quantity|name|symbol|multiplier):\s*}
8
+ @regexp = /(quantity|name|symbol|multiplier):\s*/
9
9
  @text = extract_equation(text)
10
10
  @orig_text = @text
11
- @text = @text.gsub("", "-")
11
+ @text = @text.gsub('', '-')
12
12
  post_extras
13
13
  end
14
14
 
@@ -21,10 +21,10 @@ module Unitsml
21
21
  explicit_value: @extras_hash,
22
22
  root: true,
23
23
  orig_text: @orig_text,
24
- norm_text: text,
24
+ norm_text: text
25
25
  )
26
26
  update_units_exponents(formula.value, false)
27
- formula.value.first.only_instance = true if text.end_with?("-")
27
+ formula.value.first.only_instance = true if text.end_with?('-')
28
28
  formula
29
29
  end
30
30
 
@@ -33,7 +33,7 @@ module Unitsml
33
33
  if object.is_a?(Sqrt)
34
34
  object = object.value
35
35
  if object.respond_to?(:power_numerator)
36
- object.power_numerator = "0.5"
36
+ object.power_numerator = Number.new('0.5')
37
37
  else
38
38
  update_units_exponents([object], inverse, true)
39
39
  end
@@ -41,13 +41,12 @@ module Unitsml
41
41
 
42
42
  case object
43
43
  when Unit
44
- next object.power_numerator = "0.5" if sqrt
44
+ next object.power_numerator = Number.new('0.5') if sqrt
45
45
  next unless inverse
46
46
 
47
- exponent = inverse ? "-#{object&.power_numerator || '1'}" : object.power_numerator
48
- object.power_numerator = exponent&.sub(/^--+/, "")
49
- when Dimension then object.power_numerator = "0.5" if sqrt
50
- when Extender then inverse = !inverse if ["/", "//"].any?(object.symbol)
47
+ inverse ? object.inverse_power_numerator : object.power_numerator
48
+ when Dimension then object.power_numerator = Number.new('0.5') if sqrt
49
+ when Extender then inverse = !inverse if ['/', '//'].any?(object.symbol)
51
50
  when Formula then update_units_exponents(object.value, inverse)
52
51
  when Fenced then update_units_exponents([object.value], inverse, sqrt)
53
52
  end
@@ -58,7 +57,7 @@ module Unitsml
58
57
  return nil unless @regexp.match?(text)
59
58
 
60
59
  @extras_hash = {}
61
- texts_array = text&.split(",")&.map(&:strip)
60
+ texts_array = text&.split(',')&.map(&:strip)
62
61
  @text = texts_array&.shift
63
62
  texts_array&.map { |text| parse_extras(text) }
64
63
  end
@@ -66,16 +65,16 @@ module Unitsml
66
65
  def parse_extras(text)
67
66
  return nil unless @regexp.match?(text)
68
67
 
69
- key, _, value = text&.partition(":")
68
+ key, _, value = text&.partition(':')
70
69
  @extras_hash[key&.to_sym] ||= value&.strip
71
70
  end
72
71
 
73
72
  private
74
73
 
75
74
  def extract_equation(text)
76
- return text unless text&.start_with?("unitsml(")
75
+ return text unless text&.start_with?('unitsml(')
77
76
 
78
- text.delete_prefix("unitsml(").delete_suffix(")")
77
+ text.delete_prefix('unitsml(').delete_suffix(')')
79
78
  end
80
79
  end
81
80
  end
@@ -9,22 +9,22 @@ module Unitsml
9
9
  @only_instance = only_instance
10
10
  end
11
11
 
12
- def ==(object)
13
- self.class == object.class &&
14
- prefix_name == object&.prefix_name &&
15
- only_instance == object&.only_instance
12
+ def ==(other)
13
+ self.class == other.class &&
14
+ prefix_name == other&.prefix_name &&
15
+ only_instance == other&.only_instance
16
16
  end
17
17
 
18
18
  def prefix_instance
19
- @prefix ||= Unitsdb.prefixes.find_by_symbol_name(prefix_name)
19
+ @prefix_instance ||= Unitsdb.prefixes.find_by_symbol_name(prefix_name)
20
20
  end
21
21
 
22
22
  def id
23
- @id ||= prefix_instance.identifiers.find { |prefix| prefix.type == "nist" }&.id
23
+ @id ||= prefix_instance.identifiers.find { |prefix| prefix.type == 'nist' }&.id
24
24
  end
25
25
 
26
26
  def name
27
- @name ||= prefix_instance.names.find { |name| name.lang == "en" }.value
27
+ @name ||= prefix_instance.names.find { |name| name.lang == 'en' }.value
28
28
  end
29
29
 
30
30
  def prefix_symbols
@@ -35,11 +35,11 @@ module Unitsml
35
35
  symbol = Utility.string_to_html_entity(
36
36
  Utility.html_entity_to_unicode(
37
37
  prefix_symbols.html
38
- ),
38
+ )
39
39
  )
40
40
  return symbol unless only_instance
41
41
 
42
- { method_name: :mi, value: ::Mml::Mi.new(value: symbol)}
42
+ { method_name: :mi, value: ::Mml::V4::Mi.new(value: symbol) }
43
43
  end
44
44
 
45
45
  def to_latex(_)
@@ -59,7 +59,7 @@ module Unitsml
59
59
  end
60
60
 
61
61
  def symbolid
62
- prefix_symbols.ascii if prefix_symbols
62
+ prefix_symbols&.ascii
63
63
  end
64
64
 
65
65
  def base
data/lib/unitsml/sqrt.rb CHANGED
@@ -8,9 +8,9 @@ module Unitsml
8
8
  @value = value
9
9
  end
10
10
 
11
- def ==(object)
12
- self.class == object.class &&
13
- value == object&.value
11
+ def ==(other)
12
+ self.class == other.class &&
13
+ value == other&.value
14
14
  end
15
15
 
16
16
  def to_asciimath(options)