asciimath2unitsml 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,42 @@
1
+ module Asciimath2UnitsML
2
+ class Conv
3
+ def read_yaml(path)
4
+ validate_yaml(symbolize_keys(YAML
5
+ .load_file(File.join(File.join(File.dirname(__FILE__), path)))), path)
6
+ end
7
+
8
+ def symbolize_keys(hash)
9
+ return hash if hash.is_a? String
10
+
11
+ hash.inject({}) do |result, (key, value)|
12
+ new_key = case key
13
+ when String then key.to_sym
14
+ else key
15
+ end
16
+ new_value = case value
17
+ when Hash then symbolize_keys(value)
18
+ when Array then value.map { |m| symbolize_keys(m) }
19
+ else value
20
+ end
21
+ result[new_key] = new_value
22
+ result
23
+ end
24
+ end
25
+
26
+ def flip_name_and_symbol(hash)
27
+ hash.each_with_object({}) do |(_k, v), m|
28
+ next if v.name.nil? || v.name.empty?
29
+
30
+ m[v.symbolid] = v
31
+ end
32
+ end
33
+
34
+ def flip_name_and_symbols(hash)
35
+ hash.each_with_object({}) do |(_k, v), m|
36
+ next if v.name.nil? || v.name.empty?
37
+
38
+ v.symbolids.each { |s| m[s] = v }
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,14 +1,14 @@
1
1
  module Asciimath2UnitsML
2
2
  class Conv
3
- def multiplier(x)
4
- case x
3
+ def multiplier(val)
4
+ case val
5
5
  when :space
6
6
  { html: "&#xA0;", mathml: "<mo rspace='thickmathspace'>&#x2062;</mo>" }
7
7
  when :nospace
8
8
  { html: "", mathml: "<mo>&#x2062;</mo>" }
9
9
  else
10
- { html: HTMLEntities.new.encode(x),
11
- mathml: "<mo>#{HTMLEntities.new.encode(x)}</mo>" }
10
+ { html: HTMLEntities.new.encode(val),
11
+ mathml: "<mo>#{HTMLEntities.new.encode(val)}</mo>" }
12
12
  end
13
13
  end
14
14
 
@@ -33,14 +33,14 @@ module Asciimath2UnitsML
33
33
  render(normalise ? @units[u[:unit]].symbolid : u[:unit], :html)
34
34
  htmlsymbol_exponent(u, base)
35
35
  end
36
- end.join("")
36
+ end.join
37
37
  end
38
38
 
39
- def htmlsymbol_exponent(u, base)
40
- if u[:display_exponent] == "0.5"
39
+ def htmlsymbol_exponent(unit, base)
40
+ if unit[:display_exponent] == "0.5"
41
41
  base = "&#x221a;#{base}"
42
- elsif u[:display_exponent]
43
- exp = "<sup>#{u[:display_exponent].sub(/-/, '&#x2212;')}</sup>"
42
+ elsif unit[:display_exponent]
43
+ exp = "<sup>#{unit[:display_exponent].sub(/-/, '&#x2212;')}</sup>"
44
44
  base += exp
45
45
  end
46
46
  base
@@ -56,18 +56,29 @@ module Asciimath2UnitsML
56
56
  else
57
57
  mathmlsymbol1(u, normalise)
58
58
  end
59
- end.join("")
59
+ end.join
60
60
  end
61
61
 
62
- def mathmlsymbol1(u, normalise)
63
- base = render(normalise ? @units[u[:unit]].symbolid : u[:unit], :mathml)
64
- if u[:prefix]
65
- prefix = htmlent(@prefixes[u[:prefix]].html)
66
- base = base.match(/<mi mathvariant='normal'>/) ?
67
- base.sub(/<mi mathvariant='normal'>/, "<mi mathvariant='normal'>#{prefix}") :
68
- "<mrow><mi mathvariant='normal'>#{prefix}#{base}</mrow>"
62
+ def mathmlsymbol1(unit, normalise)
63
+ base = if unit[:dim]
64
+ render(normalise ? @dimensions[unit[:dim]].symbolid : unit[:dim],
65
+ :mathml)
66
+ else
67
+ render(normalise ? @units[unit[:unit]].symbolid : unit[:unit],
68
+ :mathml)
69
+ end
70
+ unit[:prefix] and base = mathmlsymbol1_prefixed(unit, base)
71
+ mathmlsymbol_exponent(unit, base)
72
+ end
73
+
74
+ def mathmlsymbol1_prefixed(unit, base)
75
+ prefix = htmlent(@prefixes[unit[:prefix]].html)
76
+ if /<mi mathvariant='normal'>/.match?(base)
77
+ base.sub(/<mi mathvariant='normal'>/,
78
+ "<mi mathvariant='normal'>#{prefix}")
79
+ else
80
+ "<mrow><mi mathvariant='normal'>#{prefix}#{base}</mrow>"
69
81
  end
70
- mathmlsymbol_exponent(u, base)
71
82
  end
72
83
 
73
84
  def mathmlsymbol_exponent(unit, base)
@@ -7,16 +7,16 @@ module Asciimath2UnitsML
7
7
  def unit_id(text)
8
8
  text = text.gsub(/[()]/, "")
9
9
  /-$/.match(text) and return @prefixes[text.sub(/-$/, "")].id
10
- "U_" + (@units[text] ? @units[text].id.gsub(/'/, "_") : text.gsub(/\*/, ".").gsub(/\^/, ""))
10
+ "U_#{@units[text] ? @units[text].id.gsub(/'/, '_') : text.gsub(/\*/, '.').gsub(/\^/, '')}"
11
11
  end
12
12
 
13
- def unit(units, origtext, normtext, dims, name)
13
+ def unit(units, _origtext, normtext, dims, name)
14
14
  return if units_only(units).any? { |x| x[:unit].nil? }
15
15
 
16
16
  dimid = dim_id(dims)
17
17
  norm_units = normalise_units(units)
18
18
  <<~XML
19
- <Unit xmlns='#{UNITSML_NS}' xml:id='#{unit_id(normtext)}'#{dimid ? " dimensionURL='##{dimid}'" : ""}>
19
+ <Unit xmlns='#{UNITSML_NS}' xml:id='#{unit_id(normtext)}'#{dimid ? " dimensionURL='##{dimid}'" : ''}>
20
20
  #{unitsystem(units)}
21
21
  #{unitname(norm_units, normtext, name)}
22
22
  #{unitsymbol(norm_units)}
@@ -43,8 +43,10 @@ module Asciimath2UnitsML
43
43
  units.any? { |x| @units[x[:unit]].system_name != "SI" } and
44
44
  ret << "<UnitSystem name='not_SI' type='not_SI' xml:lang='en-US'/>"
45
45
  if units.any? { |x| @units[x[:unit]].system_name == "SI" }
46
- base = units.size == 1 && @units[units[0][:unit]].system_type == "SI-base"
47
- base = true if units.size == 1 && units[0][:unit] == "g" && units[0][:prefix] == "k"
46
+ base = units.size == 1 &&
47
+ @units[units[0][:unit]].system_type == "SI-base"
48
+ base = true if units.size == 1 && units[0][:unit] == "g" &&
49
+ units[0][:prefix] == "k"
48
50
  ret << "<UnitSystem name='SI' type='#{base ? 'SI_base' : 'SI_derived'}' xml:lang='en-US'/>"
49
51
  end
50
52
  ret.join("\n")
@@ -56,7 +58,7 @@ module Asciimath2UnitsML
56
58
  end
57
59
 
58
60
  # TODO: compose name from the component units
59
- def compose_name(units, text)
61
+ def compose_name(_units, text)
60
62
  text
61
63
  end
62
64
 
@@ -74,8 +76,8 @@ module Asciimath2UnitsML
74
76
  exp = units_only(units).map do |u|
75
77
  prefix = " prefix='#{u[:prefix]}'" if u[:prefix]
76
78
  u[:exponent] && u[:exponent] != "1" and
77
- exponent = " powerNumerator='#{u[:exponent]}'"
78
- "<EnumeratedRootUnit unit='#{@units[u[:unit]].name}'#{prefix}#{exponent}/>"
79
+ arg = " powerNumerator='#{u[:exponent]}'"
80
+ "<EnumeratedRootUnit unit='#{@units[u[:unit]].name}'#{prefix}#{arg}/>"
79
81
  end.join("\n")
80
82
  <<~XML
81
83
  <RootUnits>#{exp}</RootUnits>
@@ -15,41 +15,43 @@ module Asciimath2UnitsML
15
15
  def validate_unit(unit)
16
16
  if unit[:quantity_reference]
17
17
  unit[:quantity_reference].is_a?(Array) or
18
- raise StandardError.new "No quantity_reference array provided for unit: #{unit}"
18
+ raise StandardError
19
+ .new "No quantity_reference array provided for unit: #{unit}"
19
20
  end
20
21
  if unit[:unit_name]
21
22
  unit[:unit_name].is_a?(Array) or
22
- raise StandardError.new "No unit_name array provided for unit: #{unit}"
23
+ raise StandardError
24
+ .new "No unit_name array provided for unit: #{unit}"
23
25
  end
24
26
  end
25
27
 
26
- def validate_symbols(m, v)
27
- symbol = symbol_key(v)
28
+ def validate_symbols(acc, val)
29
+ symbol = symbol_key(val)
28
30
  !symbol.nil? or
29
- raise StandardError.new "No symbol provided for unit: #{v}"
31
+ raise StandardError.new "No symbol provided for unit: #{val}"
30
32
  Array(symbol)&.each do |s|
31
- m[s] && s != "1" and
32
- raise StandardError.new "symbol #{s} is not unique in #{v}: "\
33
- "already used for #{m[s]}"
34
- m[s] = v
33
+ acc[s] && s != "1" and
34
+ raise StandardError.new "symbol #{s} is not unique in #{val}: "\
35
+ "already used for #{acc[s]}"
36
+ acc[s] = val
35
37
  end
36
- m
38
+ acc
37
39
  end
38
40
 
39
- def validate_unit_symbol_cardinality(sym, k)
41
+ def validate_unit_symbol_cardinality(sym, key)
40
42
  return true if sym.nil?
41
43
 
42
44
  !sym[:id].nil? && !sym[:ascii].nil? && !sym[:html].nil? &&
43
45
  !sym[:mathml].nil? && !sym[:latex].nil? &&
44
46
  !sym[:unicode].nil? and return true
45
- raise StandardError.new "malformed unit_symbol for #{k}: #{sym}"
47
+ raise StandardError.new "malformed unit_symbol for #{key}: #{sym}"
46
48
  end
47
49
 
48
- def symbol_key(v)
49
- symbol = v[:unit_symbols]&.each_with_object([]) do |s, m|
50
+ def symbol_key(val)
51
+ symbol = val[:unit_symbols]&.each_with_object([]) do |s, m|
50
52
  m << (s["id"] || s[:id])
51
- end || v.dig(:symbol, :ascii) || v[:symbol] #|| v[:short]
52
- !symbol.nil? && v[:unit_symbols] && !symbol.is_a?(Array) and
53
+ end || val.dig(:symbol, :ascii) || val[:symbol] # || val[:short]
54
+ !symbol.nil? && val[:unit_symbols] && !symbol.is_a?(Array) and
53
55
  symbol = [symbol]
54
56
  symbol
55
57
  end
@@ -1,3 +1,3 @@
1
1
  module Asciimath2UnitsML
2
- VERSION = "0.3.3".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
@@ -3,36 +3,86 @@ NISTd1:
3
3
  length:
4
4
  powerNumerator: 1
5
5
  symbol: L
6
+ dim_symbols:
7
+ - id: "dim_L"
8
+ ascii: "L"
9
+ html: "&#x1D5AB;"
10
+ mathml: "<mi mathvariant='sans-serif'>L</mi>"
11
+ latex: \ensuremath{\mathsf{L}}
12
+ unicode: "𝖫"
13
+
6
14
 
7
15
  NISTd2:
8
16
  mass:
9
17
  powerNumerator: 1
10
18
  symbol: M
19
+ dim_symbols:
20
+ - id: "dim_M"
21
+ ascii: "M"
22
+ html: "&#x1D5AC;"
23
+ mathml: "<mi mathvariant='sans-serif'>M</mi>"
24
+ latex: \ensuremath{\mathsf{M}}
25
+ unicode: "𝖬"
11
26
 
12
27
  NISTd3:
13
28
  time:
14
29
  powerNumerator: 1
15
30
  symbol: T
31
+ dim_symbols:
32
+ - id: "dim_T"
33
+ ascii: "T"
34
+ html: "&#x1D5B3;"
35
+ mathml: "<mi mathvariant='sans-serif'>T</mi>"
36
+ latex: \ensuremath{\mathsf{T}}
37
+ unicode: "𝖳"
16
38
 
17
39
  NISTd4:
18
40
  electric_current:
19
41
  powerNumerator: 1
20
42
  symbol: I
43
+ dim_symbols:
44
+ - id: "dim_T"
45
+ ascii: "T"
46
+ html: "&#x1D5A8;"
47
+ mathml: "<mi mathvariant='sans-serif'>T</mi>"
48
+ latex: \ensuremath{\mathsf{T}}
49
+ unicode: "𝖨"
21
50
 
22
51
  NISTd5:
23
52
  thermodynamic_temperature:
24
53
  powerNumerator: 1
25
- symbol:
54
+ symbol: Theta
55
+ dim_symbols:
56
+ - id: "dim_Theta"
57
+ ascii: "Theta"
58
+ html: "&#x1D760;"
59
+ mathml: "<mi mathvariant='sans-serif'>&#x398;</mi>"
60
+ latex: \ensuremath{\mathsf{\Theta}}
61
+ unicode: "𝝧"
26
62
 
27
63
  NISTd6:
28
64
  amount_of_substance:
29
65
  powerNumerator: 1
30
66
  symbol: N
67
+ dim_symbols:
68
+ - id: "dim_N"
69
+ ascii: "N"
70
+ html: "&#x1D5AD;"
71
+ mathml: "<mi mathvariant='sans-serif'>N</mi>"
72
+ latex: \ensuremath{\mathsf{N}}
73
+ unicode: "𝖭"
31
74
 
32
75
  NISTd7:
33
76
  luminous_intensity:
34
77
  powerNumerator: 1
35
78
  symbol: J
79
+ dim_symbols:
80
+ - id: "dim_J"
81
+ ascii: "J"
82
+ html: "&#x1D5A9;"
83
+ mathml: "<mi mathvariant='sans-serif'>J</mi>"
84
+ latex: \ensuremath{\mathsf{J}}
85
+ unicode: "𝖩"
36
86
 
37
87
  NISTd8:
38
88
  length:
@@ -44,6 +94,13 @@ NISTd9:
44
94
  plane_angle:
45
95
  powerNumerator: 1
46
96
  symbol: phi
97
+ dim_symbols:
98
+ - id: "dim_phi"
99
+ ascii: "phi"
100
+ html: "&#x1D785;"
101
+ mathml: "<mi mathvariant='sans-serif'>&#x3c6;</mi>"
102
+ latex: \ensuremath{\mathsf{\phi}}
103
+ unicode: "𝞅"
47
104
 
48
105
  NISTd10:
49
106
  length:
@@ -312,7 +369,7 @@ NISTd39:
312
369
  symbol: T
313
370
  thermodynamic_temperature:
314
371
  powerNumerator: -1
315
- symbol:
372
+ symbol: Theta
316
373
 
317
374
  NISTd36:
318
375
  length:
@@ -367,7 +424,7 @@ NISTd40:
367
424
  symbol: T
368
425
  thermodynamic_temperature:
369
426
  powerNumerator: -1
370
- symbol:
427
+ symbol: Theta
371
428
 
372
429
  NISTd41:
373
430
  length:
@@ -381,7 +438,7 @@ NISTd41:
381
438
  symbol: T
382
439
  thermodynamic_temperature:
383
440
  powerNumerator: -1
384
- symbol:
441
+ symbol: Theta
385
442
 
386
443
  NISTd46:
387
444
  length:
@@ -475,7 +532,7 @@ NISTd48:
475
532
  symbol: T
476
533
  thermodynamic_temperature:
477
534
  powerNumerator: -1
478
- symbol:
535
+ symbol: Theta
479
536
  amount_of_substance:
480
537
  powerNumerator: -1
481
538
  symbol: N
@@ -603,7 +660,7 @@ NISTd60:
603
660
  NISTd68:
604
661
  thermodynamic_temperature:
605
662
  powerNumerator: -1
606
- symbol:
663
+ symbol: Theta
607
664
 
608
665
  NISTd69:
609
666
  length:
@@ -617,7 +674,7 @@ NISTd69:
617
674
  symbol: T
618
675
  thermodynamic_temperature:
619
676
  powerNumerator: -1
620
- symbol:
677
+ symbol: Theta
621
678
 
622
679
  NISTd70:
623
680
  length:
@@ -639,7 +696,7 @@ NISTd71:
639
696
  symbol: T
640
697
  thermodynamic_temperature:
641
698
  powerNumerator: -1
642
- symbol:
699
+ symbol: Theta
643
700
 
644
701
  NISTd64:
645
702
  dimensionless: true
@@ -1,29 +1,49 @@
1
1
  module UnitsDB
2
2
  class Dimension
3
- attr_reader :id, :length, :mass, :time, :electric_current,
4
- :thermodynamic_temperature,
5
- :amount_of_substance, :luminous_intensity, :plane_angle, :dimensionless
3
+ attr_reader :id, :name, :symbols, :symbols_hash,
4
+ :length, :mass, :time, :electric_current,
5
+ :thermodynamic_temperature,
6
+ :amount_of_substance, :luminous_intensity, :plane_angle,
7
+ :dimensionless
6
8
 
7
9
  def initialize(id, hash)
8
- begin
9
- @id = id
10
- @dimensionless = hash[:dimensionless]
11
- hash[:length] and @length = hash[:length][:powerNumerator].to_i
12
- hash[:mass] and @mass = hash[:mass][:powerNumerator].to_i
13
- hash[:time] and @time = hash[:time][:powerNumerator].to_i
14
- hash[:electric_current] and
15
- @electric_current = hash[:electric_current][:powerNumerator].to_i
16
- hash[:thermodynamic_temperature] and
17
- @thermodynamic_temperature = hash[:thermodynamic_temperature][:powerNumerator].to_i
18
- hash[:amount_of_substance] and
19
- @amount_of_substance = hash[:amount_of_substance][:powerNumerator].to_i
20
- hash[:luminous_intensity] and
21
- @luminous_intensity = hash[:luminous_intensity][:powerNumerator].to_i
22
- hash[:plane_angle] and
23
- @plane_angle = hash[:plane_angle][:powerNumerator].to_i
24
- rescue
25
- raise StandardError.new "Parse fail on Dimension #{id}: #{hash}"
10
+ @id = id
11
+ @dimensionless = hash[:dimensionless]
12
+ init_dimension(hash)
13
+ name_dimension(hash)
14
+ rescue StandardError
15
+ raise StandardError.new "Parse fail on Dimension #{id}: #{hash}"
16
+ end
17
+
18
+ def init_dimension(hash)
19
+ hash[:length] and @length = hash[:length][:powerNumerator].to_i
20
+ hash[:mass] and @mass = hash[:mass][:powerNumerator].to_i
21
+ hash[:time] and @time = hash[:time][:powerNumerator].to_i
22
+ hash[:electric_current] and
23
+ @electric_current = hash[:electric_current][:powerNumerator].to_i
24
+ hash[:thermodynamic_temperature] and
25
+ @thermodynamic_temperature = hash[:thermodynamic_temperature][:powerNumerator].to_i
26
+ hash[:amount_of_substance] and
27
+ @amount_of_substance = hash[:amount_of_substance][:powerNumerator].to_i
28
+ hash[:luminous_intensity] and
29
+ @luminous_intensity = hash[:luminous_intensity][:powerNumerator].to_i
30
+ hash[:plane_angle] and
31
+ @plane_angle = hash[:plane_angle][:powerNumerator].to_i
32
+ end
33
+
34
+ def name_dimension(hash)
35
+ acc = %i(length mass time electric_current thermodynamic_temperature
36
+ amount_of_substance luminous_intensity plane_angle)
37
+ .each_with_object({}) do |x, m|
38
+ hash[x] and m[x] = hash[x][:powerNumerator]
26
39
  end
40
+ return unless acc.keys.size == 1 && acc.values[0] == 1
41
+
42
+ dim = acc.keys[0]
43
+ @name = dim.to_s
44
+ @symbols = hash[dim][:dim_symbols]
45
+ @symbols_hash =
46
+ @symbols&.each_with_object({}) { |h, m| m[h[:id]] = h } || {}
27
47
  end
28
48
 
29
49
  def keys
@@ -57,21 +77,27 @@ module UnitsDB
57
77
  "#{@thermodynamic_temperature}:#{@amount_of_substance}:"\
58
78
  "#{@luminous_intensity}:#{@plane_angle}"
59
79
  end
80
+
81
+ def symbolid
82
+ @symbols ? @symbols.first[:id] : nil
83
+ end
84
+
85
+ def symbolids
86
+ @symbols ? @symbols.map { |s| s[:id] } : []
87
+ end
60
88
  end
61
89
 
62
90
  class Prefix
63
91
  attr_reader :id, :name, :base, :power, :symbol
64
92
 
65
93
  def initialize(id, hash)
66
- begin
67
- @id = id
68
- @name = hash[:name]
69
- @base = hash[:base]
70
- @power = hash[:power]
71
- @symbol = hash[:symbol] # always is a hash
72
- rescue
73
- raise StandardError.new "Parse fail on Prefix #{id}: #{hash}"
74
- end
94
+ @id = id
95
+ @name = hash[:name]
96
+ @base = hash[:base]
97
+ @power = hash[:power]
98
+ @symbol = hash[:symbol] # always is a hash
99
+ rescue StandardError
100
+ raise StandardError.new "Parse fail on Prefix #{id}: #{hash}"
75
101
  end
76
102
 
77
103
  def ascii
@@ -103,16 +129,14 @@ module UnitsDB
103
129
  attr_reader :id, :dimension, :type, :names, :units
104
130
 
105
131
  def initialize(id, hash)
106
- begin
107
- @id = id
108
- @dimension = hash[:dimension_url].sub(/^#/, "")
109
- @type = hash[:quantity_type]
110
- hash[:quantity_name] and @names = hash[:quantity_name]
111
- hash[:unit_reference] and
112
- @units = hash[:unit_reference].map { |x| x[:url].sub(/^#/, "") }
113
- rescue
114
- raise StandardError.new "Parse fail on Quantity #{id}: #{hash}"
115
- end
132
+ @id = id
133
+ @dimension = hash[:dimension_url].sub(/^#/, "")
134
+ @type = hash[:quantity_type]
135
+ hash[:quantity_name] and @names = hash[:quantity_name]
136
+ hash[:unit_reference] and
137
+ @units = hash[:unit_reference].map { |x| x[:url].sub(/^#/, "") }
138
+ rescue StandardError
139
+ raise StandardError.new "Parse fail on Quantity #{id}: #{hash}"
116
140
  end
117
141
 
118
142
  def name
@@ -126,29 +150,27 @@ module UnitsDB
126
150
 
127
151
  class Unit
128
152
  attr_reader :id, :dimension, :short, :root, :unit_system, :names,
129
- :symbols, :symbols_hash, :root_units, :quantities,
130
- :si_derived_bases, :prefixed
153
+ :symbols, :symbols_hash, :root_units, :quantities,
154
+ :si_derived_bases, :prefixed
131
155
 
132
156
  def initialize(id, hash)
133
- begin
134
- @id = id
135
- @short = short
136
- @dimension = hash[:dimension_url].sub(/^#/, "")
137
- hash[:short] && !hash[:short].empty? and @short = hash[:short]
138
- @unit_system = hash[:unit_system]
139
- @names = hash[:unit_name]
140
- @symbols_hash =
141
- hash[:unit_symbols]&.each_with_object({}) { |h, m| m[h[:id]] = h } || {}
142
- @symbols = hash[:unit_symbols]
143
- hash[:root_units] and hash[:root_units][:enumerated_root_units] and
144
- @root = hash[:root_units][:enumerated_root_units]
145
- hash[:quantity_reference] and
146
- @quantities = hash[:quantity_reference].map { |x| x[:url].sub(/^#/, "") }
147
- hash[:si_derived_bases] and @si_derived_bases = hash[:si_derived_bases]
148
- @prefixed = (hash[:prefixed] == true)
149
- rescue
150
- raise StandardError.new "Parse fail on Unit #{id}: #{hash}"
151
- end
157
+ @id = id
158
+ @short = short
159
+ @dimension = hash[:dimension_url].sub(/^#/, "")
160
+ hash[:short] && !hash[:short].empty? and @short = hash[:short]
161
+ @unit_system = hash[:unit_system]
162
+ @names = hash[:unit_name]
163
+ @symbols_hash =
164
+ hash[:unit_symbols]&.each_with_object({}) { |h, m| m[h[:id]] = h } || {}
165
+ @symbols = hash[:unit_symbols]
166
+ hash[:root_units] and hash[:root_units][:enumerated_root_units] and
167
+ @root = hash[:root_units][:enumerated_root_units]
168
+ hash[:quantity_reference] and
169
+ @quantities = hash[:quantity_reference].map { |x| x[:url].sub(/^#/, "") }
170
+ hash[:si_derived_bases] and @si_derived_bases = hash[:si_derived_bases]
171
+ @prefixed = (hash[:prefixed] == true)
172
+ rescue StandardError
173
+ raise StandardError.new "Parse fail on Unit #{id}: #{hash}"
152
174
  end
153
175
 
154
176
  def system_name