unitsml 0.2.9 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependent-repos.json +5 -0
  3. data/.github/workflows/depenedent-gems.yml +16 -0
  4. data/Gemfile +10 -1
  5. data/lib/unitsml/dimension.rb +47 -38
  6. data/lib/unitsml/error.rb +8 -0
  7. data/lib/unitsml/errors/plurimath_load_error.rb +19 -0
  8. data/lib/unitsml/extender.rb +24 -10
  9. data/lib/unitsml/formula.rb +87 -55
  10. data/lib/unitsml/model/dimension.rb +42 -0
  11. data/lib/unitsml/model/dimension_quantities/amount_of_substance.rb +10 -0
  12. data/lib/unitsml/model/dimension_quantities/electric_current.rb +10 -0
  13. data/lib/unitsml/model/dimension_quantities/length.rb +10 -0
  14. data/lib/unitsml/model/dimension_quantities/luminous_intensity.rb +10 -0
  15. data/lib/unitsml/model/dimension_quantities/mass.rb +10 -0
  16. data/lib/unitsml/model/dimension_quantities/plane_angle.rb +10 -0
  17. data/lib/unitsml/model/dimension_quantities/quantity.rb +17 -0
  18. data/lib/unitsml/model/dimension_quantities/thermodynamic_temperature.rb +10 -0
  19. data/lib/unitsml/model/dimension_quantities/time.rb +10 -0
  20. data/lib/unitsml/model/prefix.rb +28 -0
  21. data/lib/unitsml/model/prefixes/name.rb +19 -0
  22. data/lib/unitsml/model/prefixes/symbol.rb +19 -0
  23. data/lib/unitsml/model/quantities/name.rb +19 -0
  24. data/lib/unitsml/model/quantity.rb +24 -0
  25. data/lib/unitsml/model/unit.rb +31 -0
  26. data/lib/unitsml/model/units/enumerated_root_unit.rb +19 -0
  27. data/lib/unitsml/model/units/name.rb +19 -0
  28. data/lib/unitsml/model/units/root_units.rb +17 -0
  29. data/lib/unitsml/model/units/symbol.rb +26 -0
  30. data/lib/unitsml/model/units/system.rb +21 -0
  31. data/lib/unitsml/parse.rb +5 -7
  32. data/lib/unitsml/parser.rb +3 -3
  33. data/lib/unitsml/prefix.rb +21 -21
  34. data/lib/unitsml/sqrt.rb +10 -10
  35. data/lib/unitsml/unit.rb +35 -35
  36. data/lib/unitsml/unitsdb/dimension.rb +88 -0
  37. data/lib/unitsml/unitsdb/dimension_quantity.rb +15 -0
  38. data/lib/unitsml/unitsdb/dimensions.rb +38 -0
  39. data/lib/unitsml/unitsdb/prefixes.rb +22 -0
  40. data/lib/unitsml/unitsdb/quantities.rb +13 -0
  41. data/lib/unitsml/unitsdb/units.rb +44 -0
  42. data/lib/unitsml/unitsdb.rb +13 -71
  43. data/lib/unitsml/utility.rb +102 -108
  44. data/lib/unitsml/version.rb +1 -1
  45. data/lib/unitsml.rb +27 -6
  46. data/unitsml.gemspec +3 -8
  47. metadata +42 -81
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ class Prefixes
6
+ class Symbol < Lutaml::Model::Serializable
7
+ attribute :type, :string
8
+ attribute :content, :string
9
+
10
+ xml do
11
+ root "PrefixSymbol"
12
+
13
+ map_attribute :type, to: :type
14
+ map_content to: :content
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Quantities
6
+ class Name < Lutaml::Model::Serializable
7
+ attribute :lang, :string, default: -> { "en-US" }
8
+ attribute :content, :string
9
+
10
+ xml do
11
+ root "QuantityName"
12
+
13
+ map_attribute :lang, to: :lang, namespace: nil, prefix: "xml", render_default: true
14
+ map_content to: :content
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "unitsml/model/quantities/name"
4
+
5
+ module Unitsml
6
+ module Model
7
+ class Quantity < Lutaml::Model::Serializable
8
+ attribute :id, :string
9
+ attribute :name, Quantities::Name, collection: true
10
+ attribute :quantity_type, :string, default: -> { "base" }
11
+ attribute :dimension_url, :string
12
+
13
+ xml do
14
+ root "Quantity"
15
+ namespace Unitsml::UNITSML_NS
16
+
17
+ map_attribute :id, to: :id, namespace: nil, prefix: "xml"
18
+ map_attribute :quantityType, to: :quantity_type, render_default: true
19
+ map_attribute :dimensionURL, to: :dimension_url
20
+ map_element :QuantityName, to: :name
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
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
+ module Unitsml
9
+ module Model
10
+ class Unit < Lutaml::Model::Serializable
11
+ attribute :id, :string
12
+ attribute :name, Units::Name
13
+ attribute :dimension_url, :string
14
+ attribute :symbol, Units::Symbol, collection: true
15
+ attribute :system, Units::System, collection: true
16
+ attribute :root_units, Units::RootUnits
17
+
18
+ xml do
19
+ root "Unit"
20
+ namespace Unitsml::UNITSML_NS
21
+
22
+ map_attribute :dimensionURL, to: :dimension_url
23
+ map_attribute :id, to: :id, namespace: nil, prefix: "xml"
24
+ map_element :UnitSystem, to: :system
25
+ map_element :UnitName, to: :name
26
+ map_element :UnitSymbol, to: :symbol
27
+ map_element :RootUnits, to: :root_units
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ class EnumeratedRootUnit < Lutaml::Model::Serializable
7
+ attribute :unit, :string
8
+ attribute :prefix, :string
9
+ attribute :power_numerator, :string
10
+
11
+ xml do
12
+ map_attribute :unit, to: :unit
13
+ map_attribute :prefix, to: :prefix
14
+ map_attribute :powerNumerator, to: :power_numerator
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ class Name < Lutaml::Model::Serializable
7
+ attribute :name, :string
8
+ attribute :lang, :string, default: -> { "en" }
9
+
10
+ xml do
11
+ root "UnitName"
12
+
13
+ map_content to: :name
14
+ map_attribute :lang, to: :lang, namespace: nil, prefix: "xml", render_default: true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "unitsml/model/units/enumerated_root_unit"
4
+
5
+ module Unitsml
6
+ module Model
7
+ module Units
8
+ class RootUnits < Lutaml::Model::Serializable
9
+ attribute :enumerated_root_unit, EnumeratedRootUnit, collection: true
10
+
11
+ xml do
12
+ map_element :EnumeratedRootUnit, to: :enumerated_root_unit
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ class Symbol < Lutaml::Model::Serializable
7
+ attribute :type, :string
8
+ attribute :content, :string
9
+
10
+ xml do
11
+ root "UnitSymbol"
12
+
13
+ map_attribute :type, to: :type
14
+ map_content to: :content, with: { from: :content_from_xml, to: :content_to_xml }
15
+ end
16
+
17
+ # Not reading any XML for now.
18
+ def content_from_xml(**); end
19
+
20
+ def content_to_xml(model, parent, doc)
21
+ doc.add_xml_fragment(parent, model.content)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Model
5
+ module Units
6
+ class System < Lutaml::Model::Serializable
7
+ attribute :name, :string
8
+ attribute :type, :string
9
+ attribute :lang, :string, default: -> { "en-US" }
10
+
11
+ xml do
12
+ root "UnitSystem"
13
+
14
+ map_attribute :name, to: :name
15
+ map_attribute :type, to: :type
16
+ map_attribute :lang, to: :lang, namespace: nil, prefix: "xml", render_default: true
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/unitsml/parse.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "parslet"
4
- require_relative "unitsdb"
4
+ require "unitsml/unitsdb"
5
5
  module Unitsml
6
6
  class Parse < Parslet::Parser
7
- include Unitsml::Unitsdb
8
-
9
7
  rule(:power) { str("^") >> intermediate_exp(number) }
10
8
  rule(:hyphen) { str("-") }
11
9
  rule(:number) { (hyphen.maybe >> match(/[0-9]/).repeat(1)).as(:integer) }
@@ -14,19 +12,19 @@ module Unitsml
14
12
  rule(:unit_and_power) { units >> power.maybe }
15
13
 
16
14
  rule(:units) do
17
- @@filtered_units ||= arr_to_expression(Unitsdb.filtered_units, "units")
15
+ @@filtered_units ||= arr_to_expression(Unitsdb.units.filtered, "units")
18
16
  end
19
17
 
20
18
  rule(:single_letter_prefixes) do
21
- @@prefixes1 ||= arr_to_expression(Unitsdb.prefixes.select { |p| p.size == 1 }, "prefixes")
19
+ @@prefixes1 ||= arr_to_expression(Unitsdb.prefixes_by_size(1), "prefixes")
22
20
  end
23
21
 
24
22
  rule(:double_letter_prefixes) do
25
- @@prefixes2 ||= arr_to_expression(Unitsdb.prefixes.select { |p| p.size == 2 }, "prefixes")
23
+ @@prefixes2 ||= arr_to_expression(Unitsdb.prefixes_by_size(2), "prefixes")
26
24
  end
27
25
 
28
26
  rule(:dimensions) do
29
- @@dimensions ||= arr_to_expression(Unitsdb.parsable_dimensions.keys, "dimensions")
27
+ @@dimensions ||= arr_to_expression(Unitsdb.dimensions.parsables.keys, "dimensions")
30
28
  end
31
29
 
32
30
  rule(:prefixes_units) do
@@ -14,10 +14,10 @@ module Unitsml
14
14
 
15
15
  def parse
16
16
  nodes = Parse.new.parse(text)
17
+ transformed = Transform.new.apply(nodes)
18
+ formula_value = transformed.is_a?(Formula) ? transformed.value : Array(transformed)
17
19
  formula = Formula.new(
18
- [
19
- Transform.new.apply(nodes),
20
- ],
20
+ formula_value,
21
21
  explicit_value: @extras_hash,
22
22
  root: true,
23
23
  orig_text: @orig_text,
@@ -15,59 +15,59 @@ module Unitsml
15
15
  only_instance == object&.only_instance
16
16
  end
17
17
 
18
- def id
19
- Unitsdb.prefixes_hash.dig(prefix_name, :id)
18
+ def prefix_instance
19
+ @prefix ||= Unitsdb.prefixes.find_by_symbol_name(prefix_name)
20
20
  end
21
21
 
22
- def name
23
- fields.dig("name")
22
+ def id
23
+ @prefix.id
24
24
  end
25
25
 
26
- def fields
27
- Unitsdb.prefixes_hash.dig(prefix_name, :fields)
26
+ def name
27
+ prefix_instance.name
28
28
  end
29
29
 
30
30
  def prefixes_symbols
31
- fields&.dig("symbol")
31
+ prefix_instance.symbol
32
32
  end
33
33
 
34
- def to_mathml
34
+ def to_mathml(_)
35
35
  symbol = Utility.string_to_html_entity(
36
36
  Utility.html_entity_to_unicode(
37
- prefixes_symbols["html"]
37
+ prefixes_symbols.html
38
38
  ),
39
39
  )
40
40
  return symbol unless only_instance
41
41
 
42
- Utility.ox_element("mi") << symbol
42
+ { method_name: :mi, value: ::Mml::Mi.new(value: symbol)}
43
43
  end
44
44
 
45
- def to_latex
46
- prefixes_symbols["latex"]
45
+ def to_latex(_)
46
+ prefixes_symbols.latex
47
47
  end
48
48
 
49
- def to_asciimath
50
- prefixes_symbols["ascii"]
49
+ def to_asciimath(_)
50
+ prefixes_symbols.ascii
51
51
  end
52
52
 
53
- def to_html
54
- prefixes_symbols["html"]
53
+ def to_html(_)
54
+ prefixes_symbols.html
55
55
  end
56
56
 
57
- def to_unicode
58
- prefixes_symbols["unicode"]
57
+ def to_unicode(_)
58
+ prefixes_symbols.unicode
59
59
  end
60
60
 
61
61
  def symbolid
62
- prefixes_symbols["ascii"] if prefixes_symbols
62
+ prefixes_symbols.ascii if prefixes_symbols
63
63
  end
64
64
 
65
65
  def base
66
- fields&.dig("base")
66
+ prefix_instance.base
67
67
  end
68
68
 
69
69
  def power
70
- fields&.dig("power")
70
+ prefix_instance.power
71
71
  end
72
72
  end
73
73
  end
data/lib/unitsml/sqrt.rb CHANGED
@@ -13,24 +13,24 @@ module Unitsml
13
13
  value == object&.value
14
14
  end
15
15
 
16
- def to_asciimath
17
- value&.to_asciimath
16
+ def to_asciimath(options)
17
+ value&.to_asciimath(options)
18
18
  end
19
19
 
20
- def to_latex
21
- value&.to_latex
20
+ def to_latex(options)
21
+ value&.to_latex(options)
22
22
  end
23
23
 
24
- def to_mathml
25
- value&.to_mathml
24
+ def to_mathml(options)
25
+ value&.to_mathml(options)
26
26
  end
27
27
 
28
- def to_html
29
- value&.to_html
28
+ def to_html(options)
29
+ value&.to_html(options)
30
30
  end
31
31
 
32
- def to_unicode
33
- value.to_unicode
32
+ def to_unicode(options)
33
+ value&.to_unicode(options)
34
34
  end
35
35
  end
36
36
  end
data/lib/unitsml/unit.rb CHANGED
@@ -19,77 +19,77 @@ module Unitsml
19
19
  power_numerator == object&.power_numerator
20
20
  end
21
21
 
22
- def fields_hash
23
- Unitsdb.units.dig(unit_name, :fields)
22
+ def unit_instance
23
+ Unitsdb.units.find_by_name(unit_name)
24
24
  end
25
25
 
26
26
  def unit_symbols
27
- symbols = fields_hash.dig("unit_symbols")
28
- symbols.find{|symbol| symbol["id"] == unit_name }
27
+ unit_instance.unit_symbols.find { |symbol| symbol.id == unit_name }
29
28
  end
30
29
 
31
30
  def numerator_value(mathml = true)
32
31
  integer = power_numerator.to_s
33
32
  unless integer.match?(/-/)
34
- return mathml ? [Ox.parse("<mn>#{integer}</mn>")] : integer
33
+ return mathml ? { mn_value: [::Mml::Mn.from_xml("<mn>#{integer}</mn>")] } : integer
35
34
  end
36
35
 
37
36
  return integer.sub(/(-)(.+)/, '&#x2212;\2') unless mathml
38
37
 
39
38
  integer = integer.sub(/(-)(.+)/, '<mn>\2</mn>')
40
- integer = Ox.parse(integer)
41
- mo_tag = (Utility.ox_element("mo") << "&#x2212;")
42
- [mo_tag, integer]
39
+ integer = ::Mml::Mn.from_xml(integer)
40
+ mo_tag = ::Mml::Mo.new(value: "&#x2212;")
41
+ { mo_value: [mo_tag], mn_value: [integer] }
43
42
  end
44
43
 
45
- def to_mathml
46
- value = unit_symbols&.dig("mathml")
47
- value = Ox.parse(value)
48
- value.nodes.insert(0, prefix.to_mathml) if prefix
44
+ def to_mathml(options)
45
+ value = unit_symbols&.mathml
46
+ tag_name = value.match(/^<(?<tag>\w+)/)[:tag]
47
+ value = ::Mml.const_get(tag_name.capitalize).from_xml(value)
48
+ value.value = "#{prefix.to_mathml(options)}#{value.value}" if prefix
49
49
  if power_numerator
50
- msup = Utility.ox_element("msup")
51
- msup << (Utility.ox_element("mrow") << value)
52
- msup << Utility.update_nodes(
53
- Utility.ox_element("mrow"),
54
- numerator_value,
50
+ value = ::Mml::Msup.new(
51
+ mrow_value: [
52
+ ::Mml::Mrow.new("#{tag_name}_value": Array(value)),
53
+ ::Mml::Mrow.new(numerator_value),
54
+ ]
55
55
  )
56
- value = msup
56
+ tag_name = :msup
57
57
  end
58
- value
58
+ { method_name: tag_name.to_sym, value: value }
59
59
  end
60
60
 
61
- def to_latex
62
- value = unit_symbols&.dig("latex")
61
+ def to_latex(options)
62
+ value = unit_symbols&.latex
63
63
  value = "#{value}^#{power_numerator}" if power_numerator
64
- value = "#{prefix.to_latex}#{value}" if prefix
64
+ value = "#{prefix.to_latex(options)}#{value}" if prefix
65
65
  value
66
66
  end
67
67
 
68
- def to_asciimath
69
- value = unit_symbols&.dig("ascii")
68
+ def to_asciimath(options)
69
+ value = unit_symbols&.ascii
70
70
  value = "#{value}^#{power_numerator}" if power_numerator
71
- value = "#{prefix.to_asciimath}#{value}" if prefix
71
+ value = "#{prefix.to_asciimath(options)}#{value}" if prefix
72
72
  value
73
73
  end
74
74
 
75
- def to_html
76
- value = unit_symbols&.dig("html")
75
+ def to_html(options)
76
+ value = unit_symbols&.html
77
77
  if power_numerator
78
78
  value = "#{value}<sup>#{numerator_value(false)}</sup>"
79
79
  end
80
- value = "#{prefix.to_html}#{value}" if prefix
80
+ value = "#{prefix.to_html(options)}#{value}" if prefix
81
81
  value
82
82
  end
83
83
 
84
- def to_unicode
85
- value = unit_symbols&.dig("unicode")
84
+ def to_unicode(options)
85
+ value = unit_symbols&.unicode
86
86
  value = "#{value}^#{power_numerator}" if power_numerator
87
- value = "#{prefix.to_unicode}#{value}" if prefix
87
+ value = "#{prefix.to_unicode(options)}#{value}" if prefix
88
88
  value
89
89
  end
90
90
 
91
91
  def enumerated_name
92
- fields_hash.dig("unit_name")&.first
92
+ unit_instance&.unit_name&.first
93
93
  end
94
94
 
95
95
  def prefix_name
@@ -97,15 +97,15 @@ module Unitsml
97
97
  end
98
98
 
99
99
  def system_type
100
- fields_hash.dig("unit_system", "type")
100
+ unit_instance.unit_system.type
101
101
  end
102
102
 
103
103
  def system_name
104
- fields_hash.dig("unit_system", "name")
104
+ unit_instance.unit_system.name
105
105
  end
106
106
 
107
107
  def si_derived_bases
108
- fields_hash.dig("si_derived_bases")
108
+ unit_instance.si_derived_bases
109
109
  end
110
110
  end
111
111
  end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Unitsdb
5
+ class Dimension
6
+ attr_accessor :vector,
7
+ :id,
8
+ :dimensionless
9
+
10
+ attr_reader :length,
11
+ :mass,
12
+ :time,
13
+ :electric_current,
14
+ :thermodynamic_temperature,
15
+ :amount_of_substance,
16
+ :luminous_intensity,
17
+ :plane_angle,
18
+ :parsables,
19
+ :parsable,
20
+ :processed_keys
21
+
22
+ def initialize
23
+ @parsables = {}
24
+ @processed_keys = []
25
+ @parsable = false
26
+ end
27
+
28
+ def length=(value)
29
+ quantities_common_code(:length, value)
30
+ end
31
+
32
+ def mass=(value)
33
+ quantities_common_code(:mass, value)
34
+ end
35
+
36
+ def time=(value)
37
+ quantities_common_code(:time, value)
38
+ end
39
+
40
+ def thermodynamic_temperature=(value)
41
+ quantities_common_code(:thermodynamic_temperature, value)
42
+ end
43
+
44
+ def amount_of_substance=(value)
45
+ quantities_common_code(:amount_of_substance, value)
46
+ end
47
+
48
+ def luminous_intensity=(value)
49
+ quantities_common_code(:luminous_intensity, value)
50
+ end
51
+
52
+ def plane_angle=(value)
53
+ quantities_common_code(:plane_angle, value)
54
+ end
55
+
56
+ def electric_current=(value)
57
+ quantities_common_code(:electric_current, value)
58
+ end
59
+
60
+ def dim_symbols
61
+ processed_keys.map { |vec| public_send(vec)&.dim_symbols&.map(&:id) }.flatten.compact
62
+ end
63
+
64
+ def processed_symbol
65
+ public_send(processed_keys.first).symbol
66
+ end
67
+
68
+ def set_vector
69
+ @vector ||= Utility::DIMS_VECTOR.map do |h|
70
+ public_send(Utility.underscore(h))&.power_numerator
71
+ end.join(":")
72
+ end
73
+
74
+ private
75
+
76
+ def quantities_common_code(instance_var, value)
77
+ return if value.nil?
78
+
79
+ instance_variable_set(:"@#{instance_var}", value)
80
+ @processed_keys << instance_var.to_s
81
+ return if value.dim_symbols.empty?
82
+
83
+ @parsable = true
84
+ value.dim_symbols_ids(@parsables, id)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Unitsdb
5
+ class DimensionQuantity
6
+ attr_accessor :power_numerator,
7
+ :symbol,
8
+ :dim_symbols
9
+
10
+ def dim_symbols_ids(hash, dim_id)
11
+ dim_symbols.each { |dim_sym| hash[dim_sym.id] = dim_id }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Unitsdb
5
+ class Dimensions
6
+ attr_accessor :dimensions
7
+
8
+ def find_by_vector(vector)
9
+ vectored
10
+ find(:vector, vector)
11
+ end
12
+
13
+ def find_by_id(d_id)
14
+ find(:id, d_id)
15
+ end
16
+
17
+ def find_parsables_by_id(d_id)
18
+ find(:id, parsables[d_id])
19
+ end
20
+
21
+ def parsables
22
+ @parsables ||= dimensions.select(&:parsables).each_with_object({}) do |dimension, object|
23
+ object.merge!(dimension.parsables)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def vectored
30
+ @vectored ||= dimensions.each(&:set_vector)
31
+ end
32
+
33
+ def find(field, matching_data)
34
+ dimensions.find { |dim| dim.send(field) == matching_data }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unitsml
4
+ module Unitsdb
5
+ class Prefixes
6
+ attr_accessor :prefixes
7
+
8
+ def find_by_symbol_name(ascii_sym)
9
+ prefixes.find { |prefix| prefix.symbol.ascii == ascii_sym }
10
+ end
11
+
12
+ def ascii_symbols
13
+ prefixes.each_with_object([]) do |prefix, names_array|
14
+ symbol = prefix.symbol.ascii
15
+ next if symbol.empty?
16
+
17
+ names_array << symbol
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end