Class: Plurimath::Math::ModelHelper
- Inherits:
-
Object
- Object
- Plurimath::Math::ModelHelper
- Defined in:
- lib/plurimath/math/model_helper.rb
Overview
Display/serialization support helpers for the Math node classes,
extracted from Plurimath::Utility (macro refactor). Deliberately a
standalone class — NOT a Utility subclass — so it does not shadow
bareword Utility references inside math files.
Constant Summary collapse
- TEXT_CLASSES =
%w[ symbol number text ].freeze
Class Method Summary collapse
- .filter_math_zone_values(value, lang:, intent: false, options: nil) ⇒ Object
- .notations_to_mask(notations) ⇒ Object
- .validate_left_right(fields = []) ⇒ Object
- .validate_math_zone(object, lang:, intent: false, options: nil) ⇒ Object
Class Method Details
.filter_math_zone_values(value, lang:, intent: false, options: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/plurimath/math/model_helper.rb', line 38 def filter_math_zone_values(value, lang:, intent: false, options: nil) return [] if value.nil? || value.empty? new_arr = [] temp_array = [] skip_index = nil value.each_with_index do |obj, index| object = obj.dup next if index == skip_index if TEXT_CLASSES.include?(object.class_name) || math_display_text_objects(object) next temp_array << (if object.is_a?(Math::Symbols::Symbol) symbol_to_text( object, lang: lang, intent: intent, options: ) else object.value end) end if temp_array.any? new_arr << Math::Function::Text.new(temp_array.join(" "), lang: lang) end temp_array = [] new_arr << object end if temp_array.any? new_arr << Math::Function::Text.new(temp_array.join(" "), lang: lang) end new_arr end |
.notations_to_mask(notations) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/plurimath/math/model_helper.rb', line 71 def notations_to_mask(notations) mask = notations.split.map do |notation| Utility::MASK_CLASSES.key(notation) end mask.compact.sum ^ 15 end |
.validate_left_right(fields = []) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/plurimath/math/model_helper.rb', line 17 def validate_left_right(fields = []) fields.each do |field| if field.is_a?(Math::Formula) && field.value.first.is_a?(Math::Function::Left) field.left_right_wrapper = true end end end |
.validate_math_zone(object, lang:, intent: false, options: nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/plurimath/math/model_helper.rb', line 25 def validate_math_zone(object, lang:, intent: false, options: nil) return false unless object if object.is_a?(Math::Formula) filter_math_zone_values(object.value, lang: lang, intent: intent, options: ).find do |value| !(value.is_a?(Math::Function::Text) || value.is_a?(Math::Symbols::Symbol)) end else !(TEXT_CLASSES.include?(object.class_name) || object.is_a?(Math::Symbols::Symbol)) end end |