unitsml 0.6.0 → 0.6.2
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.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/.rubocop_todo.yml +97 -412
- data/Gemfile +15 -14
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/lib/unitsml/dimension.rb +3 -3
- data/lib/unitsml/errors.rb +2 -2
- data/lib/unitsml/extender.rb +9 -9
- data/lib/unitsml/fenced.rb +3 -3
- data/lib/unitsml/formula.rb +29 -20
- data/lib/unitsml/intermediate_exp_rules.rb +30 -20
- data/lib/unitsml/model/dimension.rb +1 -1
- data/lib/unitsml/model/dimension_quantities.rb +8 -4
- data/lib/unitsml/model/prefix.rb +1 -1
- data/lib/unitsml/model/prefixes/name.rb +2 -2
- data/lib/unitsml/model/prefixes/symbol.rb +1 -1
- data/lib/unitsml/model/quantities/name.rb +2 -2
- data/lib/unitsml/model/quantity.rb +2 -2
- data/lib/unitsml/model/unit.rb +1 -1
- data/lib/unitsml/model/units/name.rb +2 -2
- data/lib/unitsml/model/units/root_units.rb +1 -1
- data/lib/unitsml/model/units/symbol.rb +4 -2
- data/lib/unitsml/model/units/system.rb +2 -2
- data/lib/unitsml/model/units.rb +5 -5
- data/lib/unitsml/namespace.rb +2 -2
- data/lib/unitsml/number.rb +11 -11
- data/lib/unitsml/parse.rb +30 -19
- data/lib/unitsml/parser.rb +11 -11
- data/lib/unitsml/prefix.rb +6 -4
- data/lib/unitsml/transform.rb +26 -26
- data/lib/unitsml/unit.rb +8 -6
- data/lib/unitsml/unitsdb/dimension.rb +24 -12
- data/lib/unitsml/unitsdb/dimensions.rb +4 -0
- data/lib/unitsml/unitsdb/prefix_reference.rb +3 -1
- data/lib/unitsml/unitsdb/si_derived_base.rb +14 -0
- data/lib/unitsml/unitsdb/unit.rb +11 -3
- data/lib/unitsml/unitsdb/units.rb +4 -0
- data/lib/unitsml/unitsdb.rb +9 -19
- data/lib/unitsml/utility.rb +81 -70
- data/lib/unitsml/version.rb +1 -1
- data/lib/unitsml.rb +31 -31
- data/unitsml.gemspec +22 -19
- metadata +6 -23
- data/unitsdb/Gemfile +0 -6
- data/unitsdb/LICENSE.md +0 -53
- data/unitsdb/README.adoc +0 -1253
- data/unitsdb/RELEASE-NOTES.adoc +0 -269
- data/unitsdb/dimensions.yaml +0 -1864
- data/unitsdb/prefixes.yaml +0 -874
- data/unitsdb/quantities.yaml +0 -3715
- data/unitsdb/scales.yaml +0 -97
- data/unitsdb/schemas/README.md +0 -159
- data/unitsdb/schemas/dimensions-schema.yaml +0 -153
- data/unitsdb/schemas/prefixes-schema.yaml +0 -155
- data/unitsdb/schemas/quantities-schema.yaml +0 -117
- data/unitsdb/schemas/scales-schema.yaml +0 -106
- data/unitsdb/schemas/unit_systems-schema.yaml +0 -116
- data/unitsdb/schemas/units-schema.yaml +0 -215
- data/unitsdb/spec/units_spec.rb +0 -22
- data/unitsdb/unit_systems.yaml +0 -78
- data/unitsdb/units.yaml +0 -14052
- data/unitsdb/validate_schemas.rb +0 -203
data/lib/unitsml/dimension.rb
CHANGED
|
@@ -61,7 +61,7 @@ module Unitsml
|
|
|
61
61
|
def to_xml(_)
|
|
62
62
|
attributes = {
|
|
63
63
|
symbol: dim_instance.processed_symbol,
|
|
64
|
-
power_numerator: power_numerator&.raw_value || 1
|
|
64
|
+
power_numerator: power_numerator&.raw_value || 1,
|
|
65
65
|
}
|
|
66
66
|
Model::DimensionQuantities.const_get(modelize(element_name)).new(attributes)
|
|
67
67
|
end
|
|
@@ -71,7 +71,7 @@ module Unitsml
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
def modelize(value)
|
|
74
|
-
value&.split(
|
|
74
|
+
value&.split("_")&.map(&:capitalize)&.join
|
|
75
75
|
end
|
|
76
76
|
|
|
77
77
|
private
|
|
@@ -95,7 +95,7 @@ module Unitsml
|
|
|
95
95
|
def msup_tag(value, options)
|
|
96
96
|
mathml = power_numerator.to_mathml(options)
|
|
97
97
|
msup = ::Mml::V4::Msup.new(
|
|
98
|
-
mrow_value: [::Mml::V4::Mrow.new(mi_value: [value])]
|
|
98
|
+
mrow_value: [::Mml::V4::Mrow.new(mi_value: [value])],
|
|
99
99
|
)
|
|
100
100
|
[mathml].flatten.each do |record|
|
|
101
101
|
record_values = msup.public_send("#{record[:method_name]}_value") || []
|
data/lib/unitsml/errors.rb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Unitsml
|
|
4
4
|
module Errors
|
|
5
|
-
autoload :BaseError,
|
|
6
|
-
autoload :PlurimathLoadError,
|
|
5
|
+
autoload :BaseError, "unitsml/errors/base_error"
|
|
6
|
+
autoload :PlurimathLoadError, "unitsml/errors/plurimath_load_error"
|
|
7
7
|
end
|
|
8
8
|
end
|
data/lib/unitsml/extender.rb
CHANGED
|
@@ -14,16 +14,16 @@ module Unitsml
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def to_mathml(options)
|
|
17
|
-
rspace =
|
|
18
|
-
extender = multiplier(options[:multiplier] ||
|
|
17
|
+
rspace = "thickmathspace" if options[:multiplier] == :space
|
|
18
|
+
extender = multiplier(options[:multiplier] || "⋅", unicode: true)
|
|
19
19
|
{
|
|
20
20
|
method_name: :mo,
|
|
21
|
-
value: ::Mml::V4::Mo.new(value: extender, rspace: rspace)
|
|
21
|
+
value: ::Mml::V4::Mo.new(value: extender, rspace: rspace),
|
|
22
22
|
}
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
def to_latex(options)
|
|
26
|
-
multiplier(options[:multiplier] ||
|
|
26
|
+
multiplier(options[:multiplier] || "/")
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
def to_asciimath(options)
|
|
@@ -31,7 +31,7 @@ module Unitsml
|
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def to_html(options)
|
|
34
|
-
multiplier(options[:multiplier] ||
|
|
34
|
+
multiplier(options[:multiplier] || "⋅", unicode: true, html: true)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def to_unicode(options)
|
|
@@ -46,20 +46,20 @@ module Unitsml
|
|
|
46
46
|
when :space
|
|
47
47
|
space_extender(html, unicode)
|
|
48
48
|
when :nospace
|
|
49
|
-
unicode ?
|
|
49
|
+
unicode ? "⁢" : ""
|
|
50
50
|
else
|
|
51
51
|
unicode ? Utility.string_to_html_entity(extender) : extender
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
|
|
55
55
|
def space_extender(html, unicode)
|
|
56
|
-
return
|
|
56
|
+
return " " if html
|
|
57
57
|
|
|
58
|
-
unicode ?
|
|
58
|
+
unicode ? "⁢" : " "
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def unicode_extender
|
|
62
|
-
symbol ==
|
|
62
|
+
symbol == "*" ? "·" : symbol
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
end
|
data/lib/unitsml/fenced.rb
CHANGED
|
@@ -33,10 +33,10 @@ module Unitsml
|
|
|
33
33
|
|
|
34
34
|
fenced = ::Mml::V4::Mrow.new(mo_value: [::Mml::V4::Mo.new(value: open_paren)])
|
|
35
35
|
fenced.ordered = true
|
|
36
|
-
fenced.element_order ||= [xml_order_element(
|
|
36
|
+
fenced.element_order ||= [xml_order_element("mo")]
|
|
37
37
|
[mathml].flatten.each { |record| add_math_element(fenced, record) }
|
|
38
38
|
fenced.mo_value << ::Mml::V4::Mo.new(value: close_paren)
|
|
39
|
-
fenced.element_order << xml_order_element(
|
|
39
|
+
fenced.element_order << xml_order_element("mo")
|
|
40
40
|
{ method_name: :mrow, value: fenced }
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -84,7 +84,7 @@ module Unitsml
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
def xml_order_element(tag_name)
|
|
87
|
-
Lutaml::Xml::Element.new(
|
|
87
|
+
Lutaml::Xml::Element.new("Element", tag_name)
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
def fenced_conversion_for(lang:, options:)
|
data/lib/unitsml/formula.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require "mml"
|
|
4
|
+
require "htmlentities"
|
|
5
5
|
|
|
6
6
|
module Unitsml
|
|
7
7
|
class Formula
|
|
@@ -30,14 +30,16 @@ module Unitsml
|
|
|
30
30
|
if root
|
|
31
31
|
options = update_options(options)
|
|
32
32
|
nullify_mml_models if plurimath_available?
|
|
33
|
-
math = ::Mml::V4::Math.new(display:
|
|
33
|
+
math = ::Mml::V4::Math.new(display: "block")
|
|
34
34
|
math.ordered = true
|
|
35
35
|
math.element_order ||= []
|
|
36
|
-
value.each
|
|
36
|
+
value.each do |instance|
|
|
37
|
+
process_value(math, instance.to_mathml(options))
|
|
38
|
+
end
|
|
37
39
|
generated_math = math.to_xml.gsub(%r{&(.*?)(?=</)}, '&\1')
|
|
38
40
|
reset_mml_models if plurimath_available?
|
|
39
41
|
|
|
40
|
-
generated_math.force_encoding(
|
|
42
|
+
generated_math.force_encoding("UTF-8")
|
|
41
43
|
else
|
|
42
44
|
value.map { |obj| obj.to_mathml(options) }
|
|
43
45
|
end
|
|
@@ -63,7 +65,7 @@ module Unitsml
|
|
|
63
65
|
options = update_options(options)
|
|
64
66
|
if (dimensions_array = extract_dimensions(value)).any?
|
|
65
67
|
dimensions(sort_dims(dimensions_array), options)
|
|
66
|
-
elsif @orig_text
|
|
68
|
+
elsif /-$/.match?(@orig_text)
|
|
67
69
|
prefixes(options)
|
|
68
70
|
else
|
|
69
71
|
units(options)
|
|
@@ -73,7 +75,10 @@ module Unitsml
|
|
|
73
75
|
def to_plurimath(options = {})
|
|
74
76
|
ensure_plurimath_defined!
|
|
75
77
|
options = update_options(options)
|
|
76
|
-
|
|
78
|
+
if @orig_text.match?(/-$/)
|
|
79
|
+
return Plurimath::Math.parse(to_asciimath(options),
|
|
80
|
+
:asciimath)
|
|
81
|
+
end
|
|
77
82
|
|
|
78
83
|
Plurimath::Math.parse(to_mathml(options), :mathml)
|
|
79
84
|
end
|
|
@@ -92,7 +97,7 @@ module Unitsml
|
|
|
92
97
|
when Sqrt
|
|
93
98
|
if term.value.is_a?(Dimension)
|
|
94
99
|
sqrt_term = term.value.dup
|
|
95
|
-
sqrt_term.power_numerator = Number.new(
|
|
100
|
+
sqrt_term.power_numerator = Number.new("0.5")
|
|
96
101
|
dimensions << sqrt_term
|
|
97
102
|
elsif term.value.is_a?(Fenced)
|
|
98
103
|
dimensions.concat(Array(term.value.dimensions_extraction))
|
|
@@ -124,20 +129,21 @@ module Unitsml
|
|
|
124
129
|
|
|
125
130
|
def units(options)
|
|
126
131
|
all_units = extract_units(value)
|
|
127
|
-
norm_text = all_units.map(&:xml_postprocess_name).join(
|
|
132
|
+
norm_text = all_units.map(&:xml_postprocess_name).join("*")
|
|
128
133
|
dims = Utility.units2dimensions(extract_units(value))
|
|
129
134
|
[
|
|
130
|
-
Utility.unit(all_units, self, dims, norm_text,
|
|
135
|
+
Utility.unit(all_units, self, dims, norm_text,
|
|
136
|
+
explicit_value&.dig(:name), options),
|
|
131
137
|
Utility.prefixes(all_units, options),
|
|
132
138
|
*unique_dimensions(dims, norm_text),
|
|
133
|
-
Utility.quantity(norm_text, explicit_value&.dig(:quantity))
|
|
139
|
+
Utility.quantity(norm_text, explicit_value&.dig(:quantity)),
|
|
134
140
|
].join
|
|
135
141
|
end
|
|
136
142
|
|
|
137
143
|
def unique_dimensions(dims, norm_text)
|
|
138
144
|
[
|
|
139
145
|
Utility.dimension(norm_text),
|
|
140
|
-
Utility.dimension_components(dims)
|
|
146
|
+
Utility.dimension_components(dims),
|
|
141
147
|
].uniq
|
|
142
148
|
end
|
|
143
149
|
|
|
@@ -145,30 +151,31 @@ module Unitsml
|
|
|
145
151
|
dim_id = dims.map(&:generate_id).join
|
|
146
152
|
attributes = { id: "D_#{dim_id}" }
|
|
147
153
|
dims.each { |dim| attributes.merge!(dim.xml_instances_hash(options)) }
|
|
148
|
-
Model::Dimension.new(attributes).to_xml.force_encoding(
|
|
154
|
+
Model::Dimension.new(attributes).to_xml.force_encoding("UTF-8")
|
|
149
155
|
end
|
|
150
156
|
|
|
151
157
|
def sort_dims(values)
|
|
152
158
|
dims_hash = Utility::DIM2D
|
|
153
159
|
values.sort do |first, second|
|
|
154
|
-
dims_hash.dig(first.dimension_name,
|
|
160
|
+
dims_hash.dig(first.dimension_name,
|
|
161
|
+
:order) <=> dims_hash.dig(second.dimension_name, :order)
|
|
155
162
|
end
|
|
156
163
|
end
|
|
157
164
|
|
|
158
165
|
def prefixes(options)
|
|
159
|
-
norm_text = @norm_text&.split(
|
|
160
|
-
prefix_object = Unit.new(
|
|
166
|
+
norm_text = @norm_text&.split("-")&.first
|
|
167
|
+
prefix_object = Unit.new("", prefix: Prefix.new(norm_text))
|
|
161
168
|
[
|
|
162
169
|
Utility.prefixes([prefix_object], options),
|
|
163
170
|
Utility.dimension(norm_text),
|
|
164
|
-
Utility.quantity(norm_text, explicit_value&.dig(:quantity))
|
|
171
|
+
Utility.quantity(norm_text, explicit_value&.dig(:quantity)),
|
|
165
172
|
].join
|
|
166
173
|
end
|
|
167
174
|
|
|
168
175
|
def ensure_plurimath_defined!
|
|
169
176
|
return if plurimath_available?
|
|
170
177
|
|
|
171
|
-
require
|
|
178
|
+
require "plurimath"
|
|
172
179
|
rescue LoadError
|
|
173
180
|
raise Errors::PlurimathLoadError
|
|
174
181
|
end
|
|
@@ -178,7 +185,8 @@ module Unitsml
|
|
|
178
185
|
method_value = math_instance.public_send(:"#{method_name}_value") || []
|
|
179
186
|
method_value += Array(child_hash[:value])
|
|
180
187
|
math_instance.public_send(:"#{method_name}_value=", method_value)
|
|
181
|
-
math_instance.element_order << Lutaml::Xml::Element.new(
|
|
188
|
+
math_instance.element_order << Lutaml::Xml::Element.new("Element",
|
|
189
|
+
method_name.to_s)
|
|
182
190
|
end
|
|
183
191
|
|
|
184
192
|
def plurimath_available?
|
|
@@ -209,7 +217,8 @@ module Unitsml
|
|
|
209
217
|
|
|
210
218
|
multiplier = options[:multiplier] || explicit_value&.dig(:multiplier)
|
|
211
219
|
explicit_parenthesis = options.key?(:explicit_parenthesis) ? options[:explicit_parenthesis] : true
|
|
212
|
-
options.merge(multiplier: multiplier,
|
|
220
|
+
options.merge(multiplier: multiplier,
|
|
221
|
+
explicit_parenthesis: explicit_parenthesis).compact
|
|
213
222
|
end
|
|
214
223
|
end
|
|
215
224
|
end
|
|
@@ -14,28 +14,32 @@ module Unitsml
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
# Rules for prefixes_units
|
|
17
|
-
rule(:wrapper_prefixes_units_value)
|
|
17
|
+
rule(:wrapper_prefixes_units_value) do
|
|
18
|
+
int_exp_prefixes_units | prefixes_units_int_exp
|
|
19
|
+
end
|
|
18
20
|
|
|
19
|
-
rule(:extended_prefixed_units)
|
|
21
|
+
rule(:extended_prefixed_units) do
|
|
22
|
+
extender >> spaces? >> prefixes_units_int_exp.as(:sequence)
|
|
23
|
+
end
|
|
20
24
|
|
|
21
25
|
rule(:int_exp_prefixes_units) do
|
|
22
26
|
opening_paren >> spaces? >> named_int_exp_prefixes_units.as(:int_exp) >> spaces? >> closing_paren
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
rule(:implicit_extended) do
|
|
26
|
-
prefixes_units.as(:first_set) >> spaces.as(:extender) >> prefixes_units.as(:second_set) |
|
|
27
|
-
int_exp_prefixes_units.as(:first_int_exp_set) >> spaces? >> int_exp_prefixes_units.as(:second_int_exp_set) |
|
|
28
|
-
prefixes_units.as(:first_set) >> spaces? >> int_exp_prefixes_units.as(:second_int_exp_set) |
|
|
29
|
-
int_exp_prefixes_units.as(:first_int_exp_set) >> spaces? >> prefixes_units.as(:second_set)
|
|
30
|
+
(prefixes_units.as(:first_set) >> spaces.as(:extender) >> prefixes_units.as(:second_set)) |
|
|
31
|
+
(int_exp_prefixes_units.as(:first_int_exp_set) >> spaces? >> int_exp_prefixes_units.as(:second_int_exp_set)) |
|
|
32
|
+
(prefixes_units.as(:first_set) >> spaces? >> int_exp_prefixes_units.as(:second_int_exp_set)) |
|
|
33
|
+
(int_exp_prefixes_units.as(:first_int_exp_set) >> spaces? >> prefixes_units.as(:second_set))
|
|
30
34
|
end
|
|
31
35
|
|
|
32
36
|
rule(:prefixes_units_int_exp) do
|
|
33
|
-
implicit_extended.as(:implicit_extended) >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
34
|
-
implicit_extended.as(:implicit_extended) >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
35
|
-
int_exp_prefixes_units >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
36
|
-
prefixes_units >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
37
|
-
int_exp_prefixes_units >> prefixes_units_int_exp.as(:sequence).maybe |
|
|
38
|
-
prefixes_units >> prefixes_units_int_exp.as(:sequence).maybe
|
|
37
|
+
(implicit_extended.as(:implicit_extended) >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe) |
|
|
38
|
+
(implicit_extended.as(:implicit_extended) >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe) |
|
|
39
|
+
(int_exp_prefixes_units >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe) |
|
|
40
|
+
(prefixes_units >> spaces? >> extender >> spaces? >> prefixes_units_int_exp.as(:sequence).maybe) |
|
|
41
|
+
(int_exp_prefixes_units >> prefixes_units_int_exp.as(:sequence).maybe) |
|
|
42
|
+
(prefixes_units >> prefixes_units_int_exp.as(:sequence).maybe)
|
|
39
43
|
end
|
|
40
44
|
|
|
41
45
|
rule(:prefixes_units_named_int_exp) do
|
|
@@ -43,16 +47,16 @@ module Unitsml
|
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
rule(:named_int_exp_prefixes_units) do
|
|
46
|
-
prefixes_units_named_int_exp.as(:int_exp) >> (prefixes_units_int_exp | extended_prefixed_units).maybe |
|
|
50
|
+
(prefixes_units_named_int_exp.as(:int_exp) >> (prefixes_units_int_exp | extended_prefixed_units).maybe) |
|
|
47
51
|
prefixes_units_int_exp
|
|
48
52
|
end
|
|
49
53
|
|
|
50
54
|
# Rules for dimension_rules
|
|
51
55
|
rule(:dimension_rules_int_exp) do
|
|
52
|
-
dimension_rules.as(:first_set) >> spaces.as(:extender) >> dimension_rules.as(:second_set) >> dimension_rules_int_exp.maybe |
|
|
53
|
-
dimension_rules.as(:first_set) >> spaces? >> int_exp_dimension_rules.as(:second_int_exp_set) >> dimension_rules_int_exp.maybe |
|
|
54
|
-
int_exp_dimension_rules.as(:first_int_exp_set) >> spaces? >> dimension_rules.as(:second_set) >> dimension_rules_int_exp.maybe |
|
|
55
|
-
int_exp_dimension_rules.as(:first_int_exp_set) >> spaces? >> int_exp_dimension_rules.as(:second_int_exp_set) >> dimension_rules_int_exp.maybe |
|
|
56
|
+
(dimension_rules.as(:first_set) >> spaces.as(:extender) >> dimension_rules.as(:second_set) >> dimension_rules_int_exp.maybe) |
|
|
57
|
+
(dimension_rules.as(:first_set) >> spaces? >> int_exp_dimension_rules.as(:second_int_exp_set) >> dimension_rules_int_exp.maybe) |
|
|
58
|
+
(int_exp_dimension_rules.as(:first_int_exp_set) >> spaces? >> dimension_rules.as(:second_set) >> dimension_rules_int_exp.maybe) |
|
|
59
|
+
(int_exp_dimension_rules.as(:first_int_exp_set) >> spaces? >> int_exp_dimension_rules.as(:second_int_exp_set) >> dimension_rules_int_exp.maybe) |
|
|
56
60
|
int_exp_dimension_rules |
|
|
57
61
|
dimension_rules
|
|
58
62
|
end
|
|
@@ -61,16 +65,22 @@ module Unitsml
|
|
|
61
65
|
opening_paren >> dimension_rules_named_exp.as(:int_exp) >> closing_paren >> extended_dimension_rules.maybe
|
|
62
66
|
end
|
|
63
67
|
|
|
64
|
-
rule(:extended_dimension_rules)
|
|
68
|
+
rule(:extended_dimension_rules) do
|
|
69
|
+
spaces? >> extender >> spaces? >> dimension_rules_int_exp.as(:sequence)
|
|
70
|
+
end
|
|
65
71
|
rule(:dimension_rules_named_exp) do
|
|
66
72
|
((opening_paren.as(:open_paren) >> dimension_rules_int_exp.as(:int_exp) >> closing_paren.as(:close_paren)).as(:int_exp) >> spaces? >> (dimension_rules_int_exp | extended_dimension_rules).as(:sequence).maybe) |
|
|
67
73
|
dimension_rules_int_exp
|
|
68
74
|
end
|
|
69
75
|
|
|
70
76
|
# Rules for dimensions
|
|
71
|
-
rule(:sqrt_dimensions)
|
|
77
|
+
rule(:sqrt_dimensions) do
|
|
78
|
+
sqrt >> opening_paren >> dimension_rules_int_exp.as(:sqrt) >> closing_paren
|
|
79
|
+
end
|
|
72
80
|
|
|
73
81
|
# Rules for sequence
|
|
74
|
-
rule(:sqrt_sequence)
|
|
82
|
+
rule(:sqrt_sequence) do
|
|
83
|
+
sqrt >> opening_paren >> prefixes_units_int_exp.as(:sqrt) >> closing_paren
|
|
84
|
+
end
|
|
75
85
|
end
|
|
76
86
|
end
|
|
@@ -3,14 +3,18 @@
|
|
|
3
3
|
module Unitsml
|
|
4
4
|
module Model
|
|
5
5
|
module DimensionQuantities
|
|
6
|
-
autoload :AmountOfSubstance,
|
|
7
|
-
|
|
6
|
+
autoload :AmountOfSubstance,
|
|
7
|
+
"#{__dir__}/dimension_quantities/amount_of_substance"
|
|
8
|
+
autoload :ElectricCurrent,
|
|
9
|
+
"#{__dir__}/dimension_quantities/electric_current"
|
|
8
10
|
autoload :Length, "#{__dir__}/dimension_quantities/length"
|
|
9
|
-
autoload :LuminousIntensity,
|
|
11
|
+
autoload :LuminousIntensity,
|
|
12
|
+
"#{__dir__}/dimension_quantities/luminous_intensity"
|
|
10
13
|
autoload :Mass, "#{__dir__}/dimension_quantities/mass"
|
|
11
14
|
autoload :PlaneAngle, "#{__dir__}/dimension_quantities/plane_angle"
|
|
12
15
|
autoload :Quantity, "#{__dir__}/dimension_quantities/quantity"
|
|
13
|
-
autoload :ThermodynamicTemperature,
|
|
16
|
+
autoload :ThermodynamicTemperature,
|
|
17
|
+
"#{__dir__}/dimension_quantities/thermodynamic_temperature"
|
|
14
18
|
autoload :Time, "#{__dir__}/dimension_quantities/time"
|
|
15
19
|
end
|
|
16
20
|
end
|
data/lib/unitsml/model/prefix.rb
CHANGED
|
@@ -4,11 +4,11 @@ module Unitsml
|
|
|
4
4
|
module Model
|
|
5
5
|
module Prefixes
|
|
6
6
|
class Name < Lutaml::Model::Serializable
|
|
7
|
-
attribute :lang, :xml_lang, default: -> {
|
|
7
|
+
attribute :lang, :xml_lang, default: -> { "en" }
|
|
8
8
|
attribute :content, :string
|
|
9
9
|
|
|
10
10
|
xml do
|
|
11
|
-
element
|
|
11
|
+
element "PrefixName"
|
|
12
12
|
namespace ::Unitsml::Namespace
|
|
13
13
|
|
|
14
14
|
map_attribute :lang, to: :lang, render_default: true
|
|
@@ -4,11 +4,11 @@ module Unitsml
|
|
|
4
4
|
module Model
|
|
5
5
|
module Quantities
|
|
6
6
|
class Name < Lutaml::Model::Serializable
|
|
7
|
-
attribute :lang, :xml_lang, default: -> {
|
|
7
|
+
attribute :lang, :xml_lang, default: -> { "en" }
|
|
8
8
|
attribute :content, :string
|
|
9
9
|
|
|
10
10
|
xml do
|
|
11
|
-
element
|
|
11
|
+
element "QuantityName"
|
|
12
12
|
namespace ::Unitsml::Namespace
|
|
13
13
|
|
|
14
14
|
map_attribute :lang, to: :lang, render_default: true
|
|
@@ -5,12 +5,12 @@ module Unitsml
|
|
|
5
5
|
class Quantity < Lutaml::Model::Serializable
|
|
6
6
|
attribute :id, :xml_id
|
|
7
7
|
attribute :name, Quantities::Name, collection: true
|
|
8
|
-
attribute :quantity_type, :string, default: -> {
|
|
8
|
+
attribute :quantity_type, :string, default: -> { "base" }
|
|
9
9
|
attribute :dimension_url, :string
|
|
10
10
|
|
|
11
11
|
xml do
|
|
12
12
|
namespace ::Unitsml::Namespace
|
|
13
|
-
element
|
|
13
|
+
element "Quantity"
|
|
14
14
|
|
|
15
15
|
map_attribute :id, to: :id
|
|
16
16
|
map_attribute :quantityType, to: :quantity_type, render_default: true
|
data/lib/unitsml/model/unit.rb
CHANGED
|
@@ -5,10 +5,10 @@ module Unitsml
|
|
|
5
5
|
module Units
|
|
6
6
|
class Name < Lutaml::Model::Serializable
|
|
7
7
|
attribute :name, :string
|
|
8
|
-
attribute :lang, :xml_lang, default: -> {
|
|
8
|
+
attribute :lang, :xml_lang, default: -> { "en" }
|
|
9
9
|
|
|
10
10
|
xml do
|
|
11
|
-
element
|
|
11
|
+
element "UnitName"
|
|
12
12
|
namespace ::Unitsml::Namespace
|
|
13
13
|
|
|
14
14
|
map_content to: :name
|
|
@@ -8,11 +8,13 @@ module Unitsml
|
|
|
8
8
|
attribute :content, :string
|
|
9
9
|
|
|
10
10
|
xml do
|
|
11
|
-
element
|
|
11
|
+
element "UnitSymbol"
|
|
12
12
|
namespace ::Unitsml::Namespace
|
|
13
13
|
|
|
14
14
|
map_attribute :type, to: :type
|
|
15
|
-
map_content to: :content,
|
|
15
|
+
map_content to: :content,
|
|
16
|
+
with: { from: :content_from_xml,
|
|
17
|
+
to: :content_to_xml }
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
# Not reading any XML for now.
|
|
@@ -6,10 +6,10 @@ module Unitsml
|
|
|
6
6
|
class System < Lutaml::Model::Serializable
|
|
7
7
|
attribute :name, :string
|
|
8
8
|
attribute :type, :string
|
|
9
|
-
attribute :lang, :xml_lang, default: -> {
|
|
9
|
+
attribute :lang, :xml_lang, default: -> { "en" }
|
|
10
10
|
|
|
11
11
|
xml do
|
|
12
|
-
element
|
|
12
|
+
element "UnitSystem"
|
|
13
13
|
namespace ::Unitsml::Namespace
|
|
14
14
|
|
|
15
15
|
map_attribute :name, to: :name
|
data/lib/unitsml/model/units.rb
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
module Unitsml
|
|
4
4
|
module Model
|
|
5
5
|
module Units
|
|
6
|
-
autoload :EnumeratedRootUnit,
|
|
7
|
-
autoload :Name,
|
|
8
|
-
autoload :RootUnits,
|
|
9
|
-
autoload :Symbol,
|
|
10
|
-
autoload :System,
|
|
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
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
data/lib/unitsml/namespace.rb
CHANGED
data/lib/unitsml/number.rb
CHANGED
|
@@ -20,11 +20,11 @@ module Unitsml
|
|
|
20
20
|
matched_value = value&.match(/-?(.+)/)
|
|
21
21
|
mn_value = matched_value ? matched_value[1] : value
|
|
22
22
|
mn_tag = ::Mml::V4::Mn.new(value: mn_value)
|
|
23
|
-
value.start_with?(
|
|
23
|
+
value.start_with?("-") ? mrow_hash(mn_tag) : mn_hash(mn_tag)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def to_html(_options)
|
|
27
|
-
value.sub(
|
|
27
|
+
value.sub("-", "−")
|
|
28
28
|
end
|
|
29
29
|
|
|
30
30
|
def to_latex(_options)
|
|
@@ -40,21 +40,21 @@ module Unitsml
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def negative?
|
|
43
|
-
value.start_with?(
|
|
43
|
+
value.start_with?("-")
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def update_negative_sign
|
|
47
47
|
self.value = if negative?
|
|
48
|
-
value.delete_prefix(
|
|
48
|
+
value.delete_prefix("-")
|
|
49
49
|
else
|
|
50
|
-
[
|
|
50
|
+
["-", value].join
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
def float_to_display
|
|
55
|
-
return
|
|
55
|
+
return "" if value.nil?
|
|
56
56
|
|
|
57
|
-
value.to_f.round(1).to_s.sub(/\.0$/,
|
|
57
|
+
value.to_f.round(1).to_s.sub(/\.0$/, "")
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
private
|
|
@@ -63,16 +63,16 @@ module Unitsml
|
|
|
63
63
|
{
|
|
64
64
|
method_name: :mrow,
|
|
65
65
|
value: ::Mml::V4::Mrow.new(
|
|
66
|
-
mo_value: [::Mml::V4::Mo.new(value:
|
|
67
|
-
mn_value: [mn_tag]
|
|
68
|
-
)
|
|
66
|
+
mo_value: [::Mml::V4::Mo.new(value: "−")],
|
|
67
|
+
mn_value: [mn_tag],
|
|
68
|
+
),
|
|
69
69
|
}
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
def mn_hash(mn_tag)
|
|
73
73
|
{
|
|
74
74
|
method_name: :mn,
|
|
75
|
-
value: mn_tag
|
|
75
|
+
value: mn_tag,
|
|
76
76
|
}
|
|
77
77
|
end
|
|
78
78
|
end
|