Class: Plurimath::Asciimath::Utility
- Inherits:
-
Utility
- Object
- Utility
- Plurimath::Asciimath::Utility
- Defined in:
- lib/plurimath/asciimath/utility.rb
Overview
AsciiMath-specific helpers extracted from Plurimath::Utility (code-quality
refactor). Subclasses Utility so bareword Utility.<generic> calls inside
AsciiMath files keep resolving here and inherit the generic helpers.
Class Method Summary collapse
- .asciimath_symbol_object(value, lang: :asciimath) ⇒ Object
- .frac_values(object) ⇒ Object
- .td_value(td_object) ⇒ Object
- .td_values(objects, slicer) ⇒ Object
Class Method Details
.asciimath_symbol_object(value, lang: :asciimath) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/plurimath/asciimath/utility.rb', line 39 def asciimath_symbol_object(value, lang: :asciimath) return if value.nil? symbols = symbols_hash(lang) return symbols[value&.to_s].new if symbols.key?(value&.to_s) symbol_object(value&.to_s, lang: lang) end |
.frac_values(object) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/plurimath/asciimath/utility.rb', line 30 def frac_values(object) case object when Math::Formula object.value.any? { |d| symbol_value(d, ",") } when Array object.any? { |d| symbol_value(d, ",") } end end |
.td_value(td_object) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/plurimath/asciimath/utility.rb', line 21 def td_value(td_object) str_classes = [String, Parslet::Slice] if str_classes.include?(td_object.class) && td_object.to_s.empty? return Math::Function::Text.new(nil) end td_object end |
.td_values(objects, slicer) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/plurimath/asciimath/utility.rb', line 10 def td_values(objects, slicer) sliced = objects.slice_when { |object, _| symbol_value(object, slicer) } tds = sliced.map do |slice| Math::Function::Td.new( slice.delete_if { |d| symbol_value(d, slicer) }.compact, ) end tds << Math::Function::Td.new([]) if symbol_value(objects.last, slicer) tds end |