plurimath 0.8.20 → 0.8.22
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/README.adoc +997 -12
- data/lib/plurimath/formatter/number_formatter.rb +8 -9
- data/lib/plurimath/formatter/numbers/fraction.rb +4 -5
- data/lib/plurimath/formatter/numbers/integer.rb +9 -4
- data/lib/plurimath/formatter/numeric_formatter.rb +1 -1
- data/lib/plurimath/formatter/standard.rb +13 -13
- data/lib/plurimath/formatter.rb +0 -1
- data/lib/plurimath/math/function/bar.rb +2 -0
- data/lib/plurimath/math/function/msgroup.rb +15 -2
- data/lib/plurimath/math/symbols/symbol.rb +6 -0
- data/lib/plurimath/mathml/constants.rb +1 -0
- data/lib/plurimath/number_formatter.rb +3 -2
- data/lib/plurimath/omml/parser.rb +2 -0
- data/lib/plurimath/version.rb +1 -1
- metadata +5 -6
- data/lib/plurimath/formatter/numbers/base.rb +0 -20
@@ -19,10 +19,14 @@ module Plurimath
|
|
19
19
|
def format(precision: nil)
|
20
20
|
data_reader[:precision] = precision || precision_from(number)
|
21
21
|
int, frac, integer_format, fraction_format, signif_format = *partition_tokens(number)
|
22
|
-
|
22
|
+
# FIX FOR:
|
23
|
+
# NotImplementedError: String#<< not supported. Mutable String methods are not supported in Opal.
|
24
|
+
result = []
|
25
|
+
result << integer_format.apply(int, data_reader)
|
23
26
|
result << fraction_format.apply(frac, data_reader, int) if frac
|
27
|
+
result = result.join
|
24
28
|
result = signif_format.apply(result, integer_format, fraction_format)
|
25
|
-
result = "+#{result}" if number.positive? && data_reader[:number_sign] ==
|
29
|
+
result = "+#{result}" if number.positive? && data_reader[:number_sign].to_s == "plus"
|
26
30
|
"#{prefix}#{result}"
|
27
31
|
end
|
28
32
|
|
@@ -58,13 +62,8 @@ module Plurimath
|
|
58
62
|
end
|
59
63
|
|
60
64
|
def round_to(number, precision)
|
61
|
-
factor = 10
|
62
|
-
|
63
|
-
((number * factor).fix / factor)
|
64
|
-
else
|
65
|
-
((number * factor).round.to_f / factor)
|
66
|
-
end
|
67
|
-
result
|
65
|
+
factor = BigDecimal(10).power(precision)
|
66
|
+
(number * factor).fix / factor
|
68
67
|
end
|
69
68
|
end
|
70
69
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Plurimath
|
4
4
|
module Formatter
|
5
5
|
module Numbers
|
6
|
-
class Fraction
|
6
|
+
class Fraction
|
7
7
|
attr_reader :decimal, :precision, :separator, :group
|
8
8
|
|
9
9
|
def initialize(symbols = {})
|
@@ -18,15 +18,14 @@ module Plurimath
|
|
18
18
|
precision = options[:precision] || @precision
|
19
19
|
return "" unless precision > 0
|
20
20
|
|
21
|
-
number =
|
21
|
+
number = format(fraction, precision)
|
22
22
|
number = digit_count_format(int, fraction, number) if @digit_count
|
23
23
|
formatted_number = change_format(number) if number
|
24
24
|
formatted_number ? decimal + formatted_number : ""
|
25
25
|
end
|
26
26
|
|
27
|
-
def format(
|
28
|
-
|
29
|
-
precision ? '0' * precision : @format
|
27
|
+
def format(number, precision)
|
28
|
+
number + "0" * (precision - number.length)
|
30
29
|
end
|
31
30
|
|
32
31
|
def format_groups(string)
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Plurimath
|
4
4
|
module Formatter
|
5
5
|
module Numbers
|
6
|
-
class Integer
|
6
|
+
class Integer
|
7
7
|
attr_reader :format, :separator, :groups
|
8
8
|
|
9
9
|
def initialize(symbols = {})
|
@@ -12,7 +12,7 @@ module Plurimath
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def apply(number, options = {})
|
15
|
-
format_groups(
|
15
|
+
format_groups(number)
|
16
16
|
end
|
17
17
|
|
18
18
|
def format_groups(string)
|
@@ -21,13 +21,18 @@ module Plurimath
|
|
21
21
|
tokens = []
|
22
22
|
|
23
23
|
tokens << chop_group(string, groups.first)
|
24
|
-
|
24
|
+
string = string[0...-tokens.first.size]
|
25
|
+
|
26
|
+
until string.empty?
|
27
|
+
tokens << chop_group(string, groups.last)
|
28
|
+
string = string[0...-tokens.last.size]
|
29
|
+
end
|
25
30
|
|
26
31
|
tokens.compact.reverse.join(separator)
|
27
32
|
end
|
28
33
|
|
29
34
|
def chop_group(string, size)
|
30
|
-
string.slice
|
35
|
+
string.slice([string.size - size, 0].max, size)
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
@@ -72,7 +72,7 @@ module Plurimath
|
|
72
72
|
|
73
73
|
def update_exponent_value(number_str)
|
74
74
|
exponent_number = BigDecimal(number_str) - 1
|
75
|
-
return exponent_number.to_i if exponent_number.negative? || @exponent_sign !=
|
75
|
+
return exponent_number.to_i if exponent_number.negative? || @exponent_sign.to_s != "plus"
|
76
76
|
|
77
77
|
"+#{exponent_number.to_i}"
|
78
78
|
end
|
@@ -8,9 +8,9 @@ module Plurimath
|
|
8
8
|
|
9
9
|
DEFAULT_OPTIONS = {
|
10
10
|
fraction_group_digits: 3,
|
11
|
-
exponent_sign:
|
11
|
+
exponent_sign: nil,
|
12
12
|
fraction_group: "'",
|
13
|
-
number_sign:
|
13
|
+
number_sign: nil,
|
14
14
|
notation: :basic,
|
15
15
|
group_digits: 3,
|
16
16
|
significant: 0,
|
@@ -35,17 +35,17 @@ module Plurimath
|
|
35
35
|
default_options = self.class::DEFAULT_OPTIONS
|
36
36
|
self.precision ||= default_options[:precision]
|
37
37
|
options ||= default_options
|
38
|
-
options[:fraction_group_digits]
|
39
|
-
options[:fraction_group]
|
40
|
-
options[:exponent_sign]
|
41
|
-
options[:group_digits]
|
42
|
-
options[:number_sign]
|
43
|
-
options[:significant]
|
44
|
-
options[:notation]
|
45
|
-
options[:decimal]
|
46
|
-
options[:group]
|
47
|
-
options[:times]
|
48
|
-
options[:e]
|
38
|
+
options[:fraction_group_digits] = default_options[:fraction_group_digits] unless options.key?(:fraction_group_digits)
|
39
|
+
options[:fraction_group] = default_options[:fraction_group] unless options.key?(:fraction_group)
|
40
|
+
options[:exponent_sign] = default_options[:exponent_sign] unless options.key?(:exponent_sign)
|
41
|
+
options[:group_digits] = default_options[:group_digits] unless options.key?(:group_digits)
|
42
|
+
options[:number_sign] = default_options[:number_sign] unless options.key?(:number_sign)
|
43
|
+
options[:significant] = default_options[:significant] unless options.key?(:significant)
|
44
|
+
options[:notation] = default_options[:notation] unless options.key?(:notation)
|
45
|
+
options[:decimal] = default_options[:decimal] unless options.key?(:decimal)
|
46
|
+
options[:group] = default_options[:group] unless options.key?(:group)
|
47
|
+
options[:times] = default_options[:times] unless options.key?(:times)
|
48
|
+
options[:e] = default_options[:e] unless options.key?(:e)
|
49
49
|
options
|
50
50
|
end
|
51
51
|
end
|
data/lib/plurimath/formatter.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require_relative "formatter/numeric_formatter"
|
4
4
|
require_relative "formatter/supported_locales"
|
5
|
-
require_relative "formatter/numbers/base"
|
6
5
|
require_relative "formatter/numbers/integer"
|
7
6
|
require_relative "formatter/numbers/fraction"
|
8
7
|
require_relative "formatter/numbers/significant"
|
@@ -78,14 +78,27 @@ module Plurimath
|
|
78
78
|
def msgroup_text; end
|
79
79
|
|
80
80
|
def msgroup_text=(value)
|
81
|
-
return
|
81
|
+
return if empty_value?(value)
|
82
82
|
|
83
|
-
if value.is_a?(Array)
|
83
|
+
if value.is_a?(Array)
|
84
84
|
@temp_mathml_order << Text.new(value.pop)
|
85
85
|
else
|
86
86
|
@temp_mathml_order << Text.new(value)
|
87
87
|
end
|
88
88
|
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def empty_value?(value)
|
93
|
+
case value
|
94
|
+
when String
|
95
|
+
value.strip.empty?
|
96
|
+
when Array
|
97
|
+
value.none? { |element| element.match?(/[\S]/) }
|
98
|
+
when NilClass
|
99
|
+
true
|
100
|
+
end
|
101
|
+
end
|
89
102
|
end
|
90
103
|
end
|
91
104
|
end
|
@@ -68,6 +68,9 @@ module Plurimath
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def to_omml_without_math_tag(_, **)
|
71
|
+
# TODO: remove this condition once to word rendering issue is resolved, plurimath/plurimath/pull/328
|
72
|
+
return if value == "⁢"
|
73
|
+
|
71
74
|
value
|
72
75
|
end
|
73
76
|
|
@@ -80,6 +83,9 @@ module Plurimath
|
|
80
83
|
end
|
81
84
|
|
82
85
|
def insert_t_tag(_, options:)
|
86
|
+
# TODO: remove this condition once to word rendering issue is resolved, plurimath/plurimath/pull/328
|
87
|
+
return if value == "⁢"
|
88
|
+
|
83
89
|
[(Utility.ox_element("r", namespace: "m") << t_tag(options: options))]
|
84
90
|
end
|
85
91
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require "bigdecimal"
|
1
2
|
require_relative "formatter"
|
2
3
|
|
3
4
|
module Plurimath
|
@@ -12,7 +13,7 @@ module Plurimath
|
|
12
13
|
end
|
13
14
|
|
14
15
|
def localized_number(number_string, locale: @locale, precision: @precision, format: {})
|
15
|
-
prev_symbols = symbols(locale).dup
|
16
|
+
prev_symbols = symbols(locale.to_sym).dup
|
16
17
|
Formatter::NumericFormatter.new(
|
17
18
|
supported_locale(locale),
|
18
19
|
localize_number: localize_number,
|
@@ -24,7 +25,7 @@ module Plurimath
|
|
24
25
|
format: format,
|
25
26
|
)
|
26
27
|
ensure
|
27
|
-
symbols(locale).replace(prev_symbols)
|
28
|
+
symbols(locale.to_sym).replace(prev_symbols)
|
28
29
|
end
|
29
30
|
|
30
31
|
def twitter_cldr_reader(locale: @locale)
|
data/lib/plurimath/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plurimath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ox
|
@@ -133,7 +133,6 @@ files:
|
|
133
133
|
- lib/plurimath/cli.rb
|
134
134
|
- lib/plurimath/formatter.rb
|
135
135
|
- lib/plurimath/formatter/number_formatter.rb
|
136
|
-
- lib/plurimath/formatter/numbers/base.rb
|
137
136
|
- lib/plurimath/formatter/numbers/fraction.rb
|
138
137
|
- lib/plurimath/formatter/numbers/integer.rb
|
139
138
|
- lib/plurimath/formatter/numbers/significant.rb
|
@@ -1787,7 +1786,7 @@ licenses:
|
|
1787
1786
|
metadata:
|
1788
1787
|
homepage_uri: https://github.com/plurimath/plurimath
|
1789
1788
|
source_code_uri: https://github.com/plurimath/plurimath
|
1790
|
-
post_install_message:
|
1789
|
+
post_install_message:
|
1791
1790
|
rdoc_options: []
|
1792
1791
|
require_paths:
|
1793
1792
|
- lib
|
@@ -1803,7 +1802,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1803
1802
|
version: '0'
|
1804
1803
|
requirements: []
|
1805
1804
|
rubygems_version: 3.3.27
|
1806
|
-
signing_key:
|
1805
|
+
signing_key:
|
1807
1806
|
specification_version: 4
|
1808
1807
|
summary: Converts LaTeX math into MathML.
|
1809
1808
|
test_files: []
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Plurimath
|
4
|
-
module Formatter
|
5
|
-
module Numbers
|
6
|
-
class Base
|
7
|
-
def interpolate(string, value, orientation = :right)
|
8
|
-
value = value.to_s
|
9
|
-
length = value.length
|
10
|
-
start = orientation == :left ? 0 : -length
|
11
|
-
|
12
|
-
string = string.dup
|
13
|
-
string = string.ljust(length, '#') if string.length < length
|
14
|
-
string[start, length] = value
|
15
|
-
string.gsub('#', '')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|