unitsml 0.5.1 → 0.6.1
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/.github/workflows/rake.yml +8 -0
- data/.github/workflows/release.yml +7 -1
- data/.gitmodules +0 -3
- data/.rubocop.yml +18 -0
- data/.rubocop_todo.yml +495 -0
- data/Gemfile +8 -3
- data/Rakefile +3 -1
- data/bin/console +1 -0
- data/docs/README.adoc +2 -2
- data/lib/unitsml/dimension.rb +48 -34
- data/lib/unitsml/errors/base_error.rb +8 -0
- data/lib/unitsml/errors/plurimath_load_error.rb +1 -1
- data/lib/unitsml/errors.rb +8 -0
- data/lib/unitsml/extender.rb +16 -11
- data/lib/unitsml/fenced.rb +28 -8
- data/lib/unitsml/fenced_numeric.rb +13 -0
- data/lib/unitsml/formula.rb +35 -26
- data/lib/unitsml/intermediate_exp_rules.rb +68 -17
- data/lib/unitsml/model/dimension.rb +4 -14
- data/lib/unitsml/model/dimension_quantities/quantity.rb +2 -0
- data/lib/unitsml/model/dimension_quantities.rb +21 -0
- data/lib/unitsml/model/prefix.rb +4 -8
- data/lib/unitsml/model/prefixes/name.rb +5 -4
- data/lib/unitsml/model/prefixes/symbol.rb +3 -2
- data/lib/unitsml/model/prefixes.rb +10 -0
- data/lib/unitsml/model/quantities/name.rb +4 -3
- data/lib/unitsml/model/quantities.rb +9 -0
- data/lib/unitsml/model/quantity.rb +4 -6
- data/lib/unitsml/model/unit.rb +4 -9
- data/lib/unitsml/model/units/enumerated_root_unit.rb +1 -0
- data/lib/unitsml/model/units/name.rb +4 -3
- data/lib/unitsml/model/units/root_units.rb +3 -2
- data/lib/unitsml/model/units/symbol.rb +5 -2
- data/lib/unitsml/model/units/system.rb +4 -3
- data/lib/unitsml/model/units.rb +13 -0
- data/lib/unitsml/model.rb +15 -0
- data/lib/unitsml/namespace.rb +8 -0
- data/lib/unitsml/number.rb +79 -0
- data/lib/unitsml/parse.rb +31 -19
- data/lib/unitsml/parser.rb +5 -6
- data/lib/unitsml/prefix.rb +11 -9
- data/lib/unitsml/sqrt.rb +3 -3
- data/lib/unitsml/transform.rb +117 -55
- data/lib/unitsml/unit.rb +43 -33
- data/lib/unitsml/unitsdb/dimension.rb +5 -3
- data/lib/unitsml/unitsdb/dimensions.rb +6 -4
- data/lib/unitsml/unitsdb/prefixes.rb +0 -2
- data/lib/unitsml/unitsdb/quantities.rb +0 -2
- data/lib/unitsml/unitsdb/units.rb +6 -4
- data/lib/unitsml/unitsdb.rb +17 -23
- data/lib/unitsml/utility.rb +91 -42
- data/lib/unitsml/version.rb +3 -1
- data/lib/unitsml.rb +56 -38
- data/unitsml.gemspec +24 -19
- metadata +29 -35
- data/lib/unitsml/error.rb +0 -8
- data/unitsdb/LICENSE.md +0 -53
- data/unitsdb/README.adoc +0 -1071
- data/unitsdb/RELEASE-NOTES.adoc +0 -269
- data/unitsdb/dimensions.yaml +0 -1512
- data/unitsdb/prefixes.yaml +0 -774
- data/unitsdb/quantities.yaml +0 -3113
- data/unitsdb/scales.yaml +0 -97
- data/unitsdb/schemas/README.md +0 -159
- data/unitsdb/schemas/dimensions-schema.yaml +0 -157
- data/unitsdb/schemas/prefixes-schema.yaml +0 -159
- data/unitsdb/schemas/quantities-schema.yaml +0 -120
- data/unitsdb/schemas/scales-schema.yaml +0 -109
- data/unitsdb/schemas/unit_systems-schema.yaml +0 -120
- data/unitsdb/schemas/units-schema.yaml +0 -219
- data/unitsdb/spec/units_spec.rb +0 -20
- data/unitsdb/unit_systems.yaml +0 -74
- data/unitsdb/units.yaml +0 -13101
- data/unitsdb/validate_schemas.rb +0 -208
data/lib/unitsml/dimension.rb
CHANGED
|
@@ -9,63 +9,59 @@ module Unitsml
|
|
|
9
9
|
@power_numerator = power_numerator
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def ==(
|
|
13
|
-
self.class ==
|
|
14
|
-
dimension_name ==
|
|
15
|
-
power_numerator ==
|
|
12
|
+
def ==(other)
|
|
13
|
+
self.class == other.class &&
|
|
14
|
+
dimension_name == other&.dimension_name &&
|
|
15
|
+
power_numerator == other&.power_numerator
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def dim_instance
|
|
19
|
-
@
|
|
19
|
+
@dim_instance ||= Unitsdb.dimensions.find_parsables_by_id(dimension_name)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def dim_symbols
|
|
23
|
-
dim_instance.send(
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def to_mathml(
|
|
27
|
-
# MathML key's value in unitsdb/dimensions.yaml
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if power_numerator
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
),
|
|
37
|
-
]
|
|
38
|
-
)
|
|
39
|
-
end
|
|
23
|
+
dim_instance.send(dim_instance.processed_keys.last).symbols.first
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def to_mathml(options)
|
|
27
|
+
# MathML key's value in unitsdb/dimensions.yaml
|
|
28
|
+
# file includes mi tags only.
|
|
29
|
+
value = ::Mml::V4::Mi.from_xml(dim_symbols.mathml)
|
|
30
|
+
method_name = if power_numerator
|
|
31
|
+
value = msup_tag(value, options)
|
|
32
|
+
:msup
|
|
33
|
+
else
|
|
34
|
+
:mi
|
|
35
|
+
end
|
|
40
36
|
{ method_name: method_name, value: value }
|
|
41
37
|
end
|
|
42
38
|
|
|
43
|
-
def to_latex(
|
|
44
|
-
power_numerator_generic_code(:latex)
|
|
39
|
+
def to_latex(options)
|
|
40
|
+
power_numerator_generic_code(:latex, options)
|
|
45
41
|
end
|
|
46
42
|
|
|
47
|
-
def to_asciimath(
|
|
48
|
-
power_numerator_generic_code(:ascii)
|
|
43
|
+
def to_asciimath(options)
|
|
44
|
+
power_numerator_generic_code(:ascii, options)
|
|
49
45
|
end
|
|
50
46
|
|
|
51
|
-
def to_unicode(
|
|
52
|
-
power_numerator_generic_code(:unicode)
|
|
47
|
+
def to_unicode(options)
|
|
48
|
+
power_numerator_generic_code(:unicode, options)
|
|
53
49
|
end
|
|
54
50
|
|
|
55
|
-
def to_html(
|
|
51
|
+
def to_html(options)
|
|
56
52
|
value = dim_symbols.html
|
|
57
|
-
value = "#{value}
|
|
53
|
+
value = "#{value}#{html_numerator_conversion(options)}" if power_numerator
|
|
58
54
|
value
|
|
59
55
|
end
|
|
60
56
|
|
|
61
57
|
def generate_id
|
|
62
|
-
"#{dimension_name.split('_').last}#{power_numerator}"
|
|
58
|
+
"#{dimension_name.split('_').last}#{power_numerator&.raw_value}"
|
|
63
59
|
end
|
|
64
60
|
|
|
65
61
|
def to_xml(_)
|
|
66
62
|
attributes = {
|
|
67
63
|
symbol: dim_instance.processed_symbol,
|
|
68
|
-
power_numerator: power_numerator || 1,
|
|
64
|
+
power_numerator: power_numerator&.raw_value || 1,
|
|
69
65
|
}
|
|
70
66
|
Model::DimensionQuantities.const_get(modelize(element_name)).new(attributes)
|
|
71
67
|
end
|
|
@@ -80,15 +76,33 @@ module Unitsml
|
|
|
80
76
|
|
|
81
77
|
private
|
|
82
78
|
|
|
83
|
-
def
|
|
79
|
+
def html_numerator_conversion(options)
|
|
80
|
+
"<sup>#{power_numerator.to_html(options)}</sup>"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def power_numerator_generic_code(method_name, options)
|
|
84
84
|
value = dim_symbols.public_send(method_name)
|
|
85
85
|
return value unless power_numerator
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
method_name = :asciimath if method_name == :ascii
|
|
88
|
+
"#{value}^#{power_numerator&.public_send(:"to_#{method_name}", options)}"
|
|
88
89
|
end
|
|
89
90
|
|
|
90
91
|
def element_name
|
|
91
92
|
dim_instance.processed_keys.first
|
|
92
93
|
end
|
|
94
|
+
|
|
95
|
+
def msup_tag(value, options)
|
|
96
|
+
mathml = power_numerator.to_mathml(options)
|
|
97
|
+
msup = ::Mml::V4::Msup.new(
|
|
98
|
+
mrow_value: [::Mml::V4::Mrow.new(mi_value: [value])],
|
|
99
|
+
)
|
|
100
|
+
[mathml].flatten.each do |record|
|
|
101
|
+
record_values = msup.public_send("#{record[:method_name]}_value") || []
|
|
102
|
+
record_values += [record[:value]]
|
|
103
|
+
msup.public_send("#{record[:method_name]}_value=", record_values)
|
|
104
|
+
end
|
|
105
|
+
msup
|
|
106
|
+
end
|
|
93
107
|
end
|
|
94
108
|
end
|
data/lib/unitsml/extender.rb
CHANGED
|
@@ -8,9 +8,9 @@ module Unitsml
|
|
|
8
8
|
@symbol = symbol
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def ==(
|
|
12
|
-
self.class ==
|
|
13
|
-
symbol ==
|
|
11
|
+
def ==(other)
|
|
12
|
+
self.class == other.class &&
|
|
13
|
+
symbol == other&.symbol
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def to_mathml(options)
|
|
@@ -18,7 +18,7 @@ module Unitsml
|
|
|
18
18
|
extender = multiplier(options[:multiplier] || "⋅", unicode: true)
|
|
19
19
|
{
|
|
20
20
|
method_name: :mo,
|
|
21
|
-
value: ::Mml::Mo.new(value: extender, rspace: rspace),
|
|
21
|
+
value: ::Mml::V4::Mo.new(value: extender, rspace: rspace),
|
|
22
22
|
}
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -35,8 +35,7 @@ module Unitsml
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
def to_unicode(options)
|
|
38
|
-
extender = options[:multiplier] ||
|
|
39
|
-
symbol == "*" ? "·" : symbol
|
|
38
|
+
extender = options[:multiplier] || unicode_extender
|
|
40
39
|
multiplier(extender)
|
|
41
40
|
end
|
|
42
41
|
|
|
@@ -45,16 +44,22 @@ module Unitsml
|
|
|
45
44
|
def multiplier(extender, unicode: false, html: false)
|
|
46
45
|
case extender
|
|
47
46
|
when :space
|
|
48
|
-
|
|
49
|
-
" "
|
|
50
|
-
else
|
|
51
|
-
unicode ? "⁢" : " "
|
|
52
|
-
end
|
|
47
|
+
space_extender(html, unicode)
|
|
53
48
|
when :nospace
|
|
54
49
|
unicode ? "⁢" : ""
|
|
55
50
|
else
|
|
56
51
|
unicode ? Utility.string_to_html_entity(extender) : extender
|
|
57
52
|
end
|
|
58
53
|
end
|
|
54
|
+
|
|
55
|
+
def space_extender(html, unicode)
|
|
56
|
+
return " " if html
|
|
57
|
+
|
|
58
|
+
unicode ? "⁢" : " "
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def unicode_extender
|
|
62
|
+
symbol == "*" ? "·" : symbol
|
|
63
|
+
end
|
|
59
64
|
end
|
|
60
65
|
end
|
data/lib/unitsml/fenced.rb
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Unitsml
|
|
2
4
|
class Fenced
|
|
5
|
+
include FencedNumeric
|
|
6
|
+
|
|
3
7
|
attr_reader :open_paren, :value, :close_paren
|
|
4
8
|
|
|
5
9
|
def initialize(open_paren, value, close_paren)
|
|
@@ -8,11 +12,11 @@ module Unitsml
|
|
|
8
12
|
@close_paren = close_paren
|
|
9
13
|
end
|
|
10
14
|
|
|
11
|
-
def ==(
|
|
12
|
-
self.class ==
|
|
13
|
-
open_paren ==
|
|
14
|
-
value ==
|
|
15
|
-
close_paren ==
|
|
15
|
+
def ==(other)
|
|
16
|
+
self.class == other.class &&
|
|
17
|
+
open_paren == other&.open_paren &&
|
|
18
|
+
value == other&.value &&
|
|
19
|
+
close_paren == other&.close_paren
|
|
16
20
|
end
|
|
17
21
|
|
|
18
22
|
def to_asciimath(options = {})
|
|
@@ -27,15 +31,31 @@ module Unitsml
|
|
|
27
31
|
mathml = value.to_mathml(options)
|
|
28
32
|
return mathml unless options[:explicit_parenthesis]
|
|
29
33
|
|
|
30
|
-
fenced = ::Mml::Mrow.new(mo_value: [::Mml::Mo.new(value: open_paren)])
|
|
34
|
+
fenced = ::Mml::V4::Mrow.new(mo_value: [::Mml::V4::Mo.new(value: open_paren)])
|
|
31
35
|
fenced.ordered = true
|
|
32
36
|
fenced.element_order ||= [xml_order_element("mo")]
|
|
33
37
|
[mathml].flatten.each { |record| add_math_element(fenced, record) }
|
|
34
|
-
fenced.mo_value << ::Mml::Mo.new(value: close_paren)
|
|
38
|
+
fenced.mo_value << ::Mml::V4::Mo.new(value: close_paren)
|
|
35
39
|
fenced.element_order << xml_order_element("mo")
|
|
36
40
|
{ method_name: :mrow, value: fenced }
|
|
37
41
|
end
|
|
38
42
|
|
|
43
|
+
def negative?
|
|
44
|
+
value.negative?
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def update_negative_sign
|
|
48
|
+
value.update_negative_sign
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def float_to_display
|
|
52
|
+
value.float_to_display
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def raw_value
|
|
56
|
+
value.raw_value
|
|
57
|
+
end
|
|
58
|
+
|
|
39
59
|
def to_html(options = {})
|
|
40
60
|
fenced_conversion_for(lang: :html, options: options)
|
|
41
61
|
end
|
|
@@ -64,7 +84,7 @@ module Unitsml
|
|
|
64
84
|
end
|
|
65
85
|
|
|
66
86
|
def xml_order_element(tag_name)
|
|
67
|
-
Lutaml::
|
|
87
|
+
Lutaml::Xml::Element.new("Element", tag_name)
|
|
68
88
|
end
|
|
69
89
|
|
|
70
90
|
def fenced_conversion_for(lang:, options:)
|
data/lib/unitsml/formula.rb
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
require "mml"
|
|
4
4
|
require "htmlentities"
|
|
5
|
-
require "unitsml/utility"
|
|
6
5
|
|
|
7
6
|
module Unitsml
|
|
8
7
|
class Formula
|
|
@@ -20,25 +19,27 @@ module Unitsml
|
|
|
20
19
|
@norm_text = norm_text
|
|
21
20
|
end
|
|
22
21
|
|
|
23
|
-
def ==(
|
|
24
|
-
self.class ==
|
|
25
|
-
value ==
|
|
26
|
-
explicit_value ==
|
|
27
|
-
root ==
|
|
22
|
+
def ==(other)
|
|
23
|
+
self.class == other.class &&
|
|
24
|
+
value == other&.value &&
|
|
25
|
+
explicit_value == other&.explicit_value &&
|
|
26
|
+
root == other.root
|
|
28
27
|
end
|
|
29
28
|
|
|
30
29
|
def to_mathml(options = {})
|
|
31
30
|
if root
|
|
32
31
|
options = update_options(options)
|
|
33
32
|
nullify_mml_models if plurimath_available?
|
|
34
|
-
math = ::Mml::
|
|
33
|
+
math = ::Mml::V4::Math.new(display: "block")
|
|
35
34
|
math.ordered = true
|
|
36
35
|
math.element_order ||= []
|
|
37
|
-
value.each
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
value.each do |instance|
|
|
37
|
+
process_value(math, instance.to_mathml(options))
|
|
38
|
+
end
|
|
39
|
+
generated_math = math.to_xml.gsub(%r{&(.*?)(?=</)}, '&\1')
|
|
40
40
|
reset_mml_models if plurimath_available?
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
generated_math.force_encoding("UTF-8")
|
|
42
43
|
else
|
|
43
44
|
value.map { |obj| obj.to_mathml(options) }
|
|
44
45
|
end
|
|
@@ -64,7 +65,7 @@ module Unitsml
|
|
|
64
65
|
options = update_options(options)
|
|
65
66
|
if (dimensions_array = extract_dimensions(value)).any?
|
|
66
67
|
dimensions(sort_dims(dimensions_array), options)
|
|
67
|
-
elsif @orig_text
|
|
68
|
+
elsif /-$/.match?(@orig_text)
|
|
68
69
|
prefixes(options)
|
|
69
70
|
else
|
|
70
71
|
units(options)
|
|
@@ -74,7 +75,10 @@ module Unitsml
|
|
|
74
75
|
def to_plurimath(options = {})
|
|
75
76
|
ensure_plurimath_defined!
|
|
76
77
|
options = update_options(options)
|
|
77
|
-
|
|
78
|
+
if @orig_text.match?(/-$/)
|
|
79
|
+
return Plurimath::Math.parse(to_asciimath(options),
|
|
80
|
+
:asciimath)
|
|
81
|
+
end
|
|
78
82
|
|
|
79
83
|
Plurimath::Math.parse(to_mathml(options), :mathml)
|
|
80
84
|
end
|
|
@@ -87,19 +91,20 @@ module Unitsml
|
|
|
87
91
|
|
|
88
92
|
def extract_dimensions(formula)
|
|
89
93
|
formula.each_with_object([]) do |term, dimensions|
|
|
90
|
-
|
|
94
|
+
case term
|
|
95
|
+
when Dimension
|
|
91
96
|
dimensions << term
|
|
92
|
-
|
|
97
|
+
when Sqrt
|
|
93
98
|
if term.value.is_a?(Dimension)
|
|
94
99
|
sqrt_term = term.value.dup
|
|
95
|
-
sqrt_term.power_numerator = "0.5"
|
|
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))
|
|
99
104
|
end
|
|
100
|
-
|
|
105
|
+
when Formula
|
|
101
106
|
dimensions.concat(extract_dimensions(term.value))
|
|
102
|
-
|
|
107
|
+
when Fenced
|
|
103
108
|
dimensions.concat(Array(term.dimensions_extraction))
|
|
104
109
|
end
|
|
105
110
|
end
|
|
@@ -127,7 +132,8 @@ module Unitsml
|
|
|
127
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
139
|
Utility.quantity(norm_text, explicit_value&.dig(:quantity)),
|
|
@@ -145,13 +151,14 @@ 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
|
|
154
|
+
Model::Dimension.new(attributes).to_xml.force_encoding("UTF-8")
|
|
149
155
|
end
|
|
150
156
|
|
|
151
157
|
def sort_dims(values)
|
|
152
|
-
dims_hash = Utility::
|
|
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
|
|
|
@@ -169,7 +176,7 @@ module Unitsml
|
|
|
169
176
|
return if plurimath_available?
|
|
170
177
|
|
|
171
178
|
require "plurimath"
|
|
172
|
-
rescue LoadError
|
|
179
|
+
rescue LoadError
|
|
173
180
|
raise Errors::PlurimathLoadError
|
|
174
181
|
end
|
|
175
182
|
|
|
@@ -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::
|
|
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?
|
|
@@ -192,7 +200,7 @@ module Unitsml
|
|
|
192
200
|
end
|
|
193
201
|
|
|
194
202
|
def reset_mml_models
|
|
195
|
-
::Mml::Configuration.custom_models = Plurimath::Mathml::Parser::CONFIGURATION
|
|
203
|
+
::Mml::V4::Configuration.custom_models = Plurimath::Mathml::Parser::CONFIGURATION
|
|
196
204
|
end
|
|
197
205
|
|
|
198
206
|
def process_value(math, mathml_instances)
|
|
@@ -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
|
|
@@ -1,35 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module Unitsml
|
|
2
4
|
module IntermediateExpRules
|
|
3
5
|
include Parslet
|
|
4
6
|
|
|
5
7
|
# Rules for slashed number
|
|
6
|
-
rule(:slashed_number_int_exp)
|
|
8
|
+
rule(:slashed_number_int_exp) do
|
|
9
|
+
slashed_number | (opening_paren >> slashed_number_named_int_exp.as(:int_exp) >> closing_paren)
|
|
10
|
+
end
|
|
11
|
+
rule(:slashed_number_named_int_exp) do
|
|
12
|
+
(opening_paren.as(:open_paren) >> slashed_number_int_exp >> closing_paren.as(:close_paren)) |
|
|
13
|
+
slashed_number_int_exp
|
|
14
|
+
end
|
|
7
15
|
|
|
8
16
|
# Rules for prefixes_units
|
|
9
|
-
rule(:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
rule(:wrapper_prefixes_units_value) do
|
|
18
|
+
int_exp_prefixes_units | prefixes_units_int_exp
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
rule(:extended_prefixed_units) do
|
|
22
|
+
extender >> spaces? >> prefixes_units_int_exp.as(:sequence)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
rule(:int_exp_prefixes_units) do
|
|
26
|
+
opening_paren >> spaces? >> named_int_exp_prefixes_units.as(:int_exp) >> spaces? >> closing_paren
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
rule(:implicit_extended) do
|
|
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))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
rule(:prefixes_units_int_exp) do
|
|
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)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
rule(:prefixes_units_named_int_exp) do
|
|
46
|
+
opening_paren.as(:open_paren) >> spaces? >> wrapper_prefixes_units_value.as(:int_exp) >> spaces? >> closing_paren.as(:close_paren)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
rule(:named_int_exp_prefixes_units) do
|
|
50
|
+
(prefixes_units_named_int_exp.as(:int_exp) >> (prefixes_units_int_exp | extended_prefixed_units).maybe) |
|
|
51
|
+
prefixes_units_int_exp
|
|
14
52
|
end
|
|
15
53
|
|
|
16
54
|
# Rules for dimension_rules
|
|
17
|
-
rule(:dimension_rules_int_exp)
|
|
18
|
-
|
|
55
|
+
rule(:dimension_rules_int_exp) do
|
|
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) |
|
|
60
|
+
int_exp_dimension_rules |
|
|
61
|
+
dimension_rules
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
rule(:int_exp_dimension_rules) do
|
|
65
|
+
opening_paren >> dimension_rules_named_exp.as(:int_exp) >> closing_paren >> extended_dimension_rules.maybe
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
rule(:extended_dimension_rules) do
|
|
69
|
+
spaces? >> extender >> spaces? >> dimension_rules_int_exp.as(:sequence)
|
|
70
|
+
end
|
|
19
71
|
rule(:dimension_rules_named_exp) do
|
|
20
|
-
|
|
21
|
-
|
|
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) |
|
|
73
|
+
dimension_rules_int_exp
|
|
22
74
|
end
|
|
23
75
|
|
|
24
76
|
# Rules for dimensions
|
|
25
|
-
rule(:sqrt_dimensions)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
rule(:dimensions_named_exp) { powered_dimensions | (str("(").as(:open_parenthesis) >> dimensions_int_exp.as(:int_exp) >> str(")").as(:close_parenthesis)) }
|
|
77
|
+
rule(:sqrt_dimensions) do
|
|
78
|
+
sqrt >> opening_paren >> dimension_rules_int_exp.as(:sqrt) >> closing_paren
|
|
79
|
+
end
|
|
29
80
|
|
|
30
81
|
# Rules for sequence
|
|
31
|
-
rule(:sqrt_sequence)
|
|
32
|
-
|
|
33
|
-
|
|
82
|
+
rule(:sqrt_sequence) do
|
|
83
|
+
sqrt >> opening_paren >> prefixes_units_int_exp.as(:sqrt) >> closing_paren
|
|
84
|
+
end
|
|
34
85
|
end
|
|
35
86
|
end
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "unitsml/model/dimension_quantities/quantity"
|
|
4
|
-
require "unitsml/model/dimension_quantities/length"
|
|
5
|
-
require "unitsml/model/dimension_quantities/mass"
|
|
6
|
-
require "unitsml/model/dimension_quantities/time"
|
|
7
|
-
require "unitsml/model/dimension_quantities/electric_current"
|
|
8
|
-
require "unitsml/model/dimension_quantities/thermodynamic_temperature"
|
|
9
|
-
require "unitsml/model/dimension_quantities/amount_of_substance"
|
|
10
|
-
require "unitsml/model/dimension_quantities/luminous_intensity"
|
|
11
|
-
require "unitsml/model/dimension_quantities/plane_angle"
|
|
12
|
-
|
|
13
3
|
module Unitsml
|
|
14
4
|
module Model
|
|
15
5
|
class Dimension < Lutaml::Model::Serializable
|
|
16
|
-
attribute :id, :
|
|
6
|
+
attribute :id, :xml_id
|
|
17
7
|
attribute :length, DimensionQuantities::Length
|
|
18
8
|
attribute :mass, DimensionQuantities::Mass
|
|
19
9
|
attribute :time, DimensionQuantities::Time
|
|
@@ -24,10 +14,10 @@ module Unitsml
|
|
|
24
14
|
attribute :plane_angle, DimensionQuantities::PlaneAngle
|
|
25
15
|
|
|
26
16
|
xml do
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
namespace ::Unitsml::Namespace
|
|
18
|
+
element "Dimension"
|
|
29
19
|
|
|
30
|
-
map_attribute :id, to: :id
|
|
20
|
+
map_attribute :id, to: :id
|
|
31
21
|
map_element :Length, to: :length
|
|
32
22
|
map_element :Mass, to: :mass
|
|
33
23
|
map_element :Time, to: :time
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Unitsml
|
|
4
|
+
module Model
|
|
5
|
+
module DimensionQuantities
|
|
6
|
+
autoload :AmountOfSubstance,
|
|
7
|
+
"#{__dir__}/dimension_quantities/amount_of_substance"
|
|
8
|
+
autoload :ElectricCurrent,
|
|
9
|
+
"#{__dir__}/dimension_quantities/electric_current"
|
|
10
|
+
autoload :Length, "#{__dir__}/dimension_quantities/length"
|
|
11
|
+
autoload :LuminousIntensity,
|
|
12
|
+
"#{__dir__}/dimension_quantities/luminous_intensity"
|
|
13
|
+
autoload :Mass, "#{__dir__}/dimension_quantities/mass"
|
|
14
|
+
autoload :PlaneAngle, "#{__dir__}/dimension_quantities/plane_angle"
|
|
15
|
+
autoload :Quantity, "#{__dir__}/dimension_quantities/quantity"
|
|
16
|
+
autoload :ThermodynamicTemperature,
|
|
17
|
+
"#{__dir__}/dimension_quantities/thermodynamic_temperature"
|
|
18
|
+
autoload :Time, "#{__dir__}/dimension_quantities/time"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/unitsml/model/prefix.rb
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "unitsml/model/prefixes/name"
|
|
4
|
-
require "unitsml/model/prefixes/symbol"
|
|
5
|
-
|
|
6
|
-
|
|
7
3
|
module Unitsml
|
|
8
4
|
module Model
|
|
9
5
|
class Prefix < Lutaml::Model::Serializable
|
|
10
6
|
attribute :name, Prefixes::Name
|
|
11
|
-
attribute :id, :
|
|
7
|
+
attribute :id, :xml_id
|
|
12
8
|
attribute :symbol, Prefixes::Symbol, collection: true
|
|
13
9
|
attribute :prefix_base, :string
|
|
14
10
|
attribute :prefix_power, :string
|
|
15
11
|
|
|
16
12
|
xml do
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
namespace ::Unitsml::Namespace
|
|
14
|
+
element "Prefix"
|
|
19
15
|
|
|
20
16
|
map_attribute :prefixBase, to: :prefix_base
|
|
21
17
|
map_attribute :prefixPower, to: :prefix_power
|
|
22
|
-
map_attribute :id, to: :id
|
|
18
|
+
map_attribute :id, to: :id
|
|
23
19
|
map_element :PrefixName, to: :name
|
|
24
20
|
map_element :PrefixSymbol, to: :symbol
|
|
25
21
|
end
|