plurimath 0.8.20 → 0.8.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- result = integer_format.apply(int, data_reader)
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] == :plus
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 ** precision
62
- result = if number.is_a?(BigDecimal)
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 < Base
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 = interpolate(format(options), fraction, :left)
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(options)
28
- precision = options[:precision] || @precision
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 < Base
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(interpolate(number, number.to_i))
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
- tokens << chop_group(string, groups.last) until string.empty?
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!([string.size - size, 0].max, size)
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 != :plus
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: "plus",
11
+ exponent_sign: nil,
12
12
  fraction_group: "'",
13
- number_sign: "plus",
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] ||= default_options[:fraction_group_digits]
39
- options[:fraction_group] ||= default_options[:fraction_group]
40
- options[:exponent_sign] ||= default_options[:exponent_sign]
41
- options[:group_digits] ||= default_options[:group_digits]
42
- options[:number_sign] ||= default_options[:number_sign]
43
- options[:significant] ||= default_options[:significant]
44
- options[:notation] ||= default_options[:notation]
45
- options[:decimal] ||= default_options[:decimal]
46
- options[:group] ||= default_options[:group]
47
- options[:times] ||= default_options[:times]
48
- options[:e] ||= default_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
@@ -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"
@@ -93,6 +93,8 @@ module Plurimath
93
93
  Utility.update_nodes(barpr, [pos, ctrlp])
94
94
  end
95
95
  end
96
+
97
+ Overline = Bar
96
98
  end
97
99
  end
98
100
  end
@@ -78,14 +78,27 @@ module Plurimath
78
78
  def msgroup_text; end
79
79
 
80
80
  def msgroup_text=(value)
81
- return unless value
81
+ return if empty_value?(value)
82
82
 
83
- if value.is_a?(Array) && value.none? { |element| element.match?(/[^\s]/) }
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
@@ -176,6 +176,7 @@ module Plurimath
176
176
  mathfrak
177
177
  underset
178
178
  stackrel
179
+ overline
179
180
  overset
180
181
  mathcal
181
182
  arccos
@@ -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)
@@ -45,6 +45,8 @@ module Plurimath
45
45
  end
46
46
 
47
47
  def parse_nodes(nodes)
48
+ nodes.delete_if { |node| node.is_xml_comment? if node.respond_to?(:is_xml_comment?) }
49
+
48
50
  nodes.map do |node|
49
51
  if node.is_a?(String)
50
52
  node == "​" ? nil : node
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Plurimath
4
- VERSION = "0.8.20"
4
+ VERSION = "0.8.21"
5
5
  end
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.20
4
+ version: 0.8.21
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-06 00:00:00.000000000 Z
11
+ date: 2025-01-26 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