Class: Unitsml::Formula
- Inherits:
-
Object
- Object
- Unitsml::Formula
- Defined in:
- lib/unitsml/formula.rb
Instance Attribute Summary collapse
-
#explicit_value ⇒ Object
Returns the value of attribute explicit_value.
-
#root ⇒ Object
Returns the value of attribute root.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(object) ⇒ Object
- #dimensions_extraction ⇒ Object
-
#initialize(value = [], explicit_value: nil, root: false, orig_text: nil, norm_text: nil) ⇒ Formula
constructor
A new instance of Formula.
- #to_asciimath(options = {}) ⇒ Object
- #to_html(options = {}) ⇒ Object
- #to_latex(options = {}) ⇒ Object
- #to_mathml(options = {}) ⇒ Object
- #to_plurimath(options = {}) ⇒ Object
- #to_unicode(options = {}) ⇒ Object
- #to_xml(options = {}) ⇒ Object
Constructor Details
#initialize(value = [], explicit_value: nil, root: false, orig_text: nil, norm_text: nil) ⇒ Formula
Returns a new instance of Formula.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/unitsml/formula.rb', line 11 def initialize(value = [], explicit_value: nil, root: false, orig_text: nil, norm_text: nil) @value = value @explicit_value = explicit_value @root = root @orig_text = orig_text @norm_text = norm_text end |
Instance Attribute Details
#explicit_value ⇒ Object
Returns the value of attribute explicit_value.
9 10 11 |
# File 'lib/unitsml/formula.rb', line 9 def explicit_value @explicit_value end |
#root ⇒ Object
Returns the value of attribute root.
9 10 11 |
# File 'lib/unitsml/formula.rb', line 9 def root @root end |
#value ⇒ Object
Returns the value of attribute value.
9 10 11 |
# File 'lib/unitsml/formula.rb', line 9 def value @value end |
Instance Method Details
#==(object) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/unitsml/formula.rb', line 23 def ==(object) self.class == object.class && value == object&.value && explicit_value == object&.explicit_value && root == object.root end |
#dimensions_extraction ⇒ Object
82 83 84 |
# File 'lib/unitsml/formula.rb', line 82 def dimensions_extraction extract_dimensions(value) end |
#to_asciimath(options = {}) ⇒ Object
51 52 53 |
# File 'lib/unitsml/formula.rb', line 51 def to_asciimath( = {}) value.map { |obj| obj.to_asciimath(()) }.join end |
#to_html(options = {}) ⇒ Object
55 56 57 |
# File 'lib/unitsml/formula.rb', line 55 def to_html( = {}) value.map { |obj| obj.to_html(()) }.join end |
#to_latex(options = {}) ⇒ Object
47 48 49 |
# File 'lib/unitsml/formula.rb', line 47 def to_latex( = {}) value.map { |obj| obj.to_latex(()) }.join end |
#to_mathml(options = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/unitsml/formula.rb', line 30 def to_mathml( = {}) if root = () nullify_mml_models if plurimath_available? math = ::Mml::MathWithNamespace.new(display: "block") math.ordered = true math.element_order ||= [] value.each { |instance| process_value(math, instance.to_mathml()) } generated_math = math.to_xml.gsub(/&(.*?)(?=<\/)/, '&\1') reset_mml_models if plurimath_available? generated_math else value.map { |obj| obj.to_mathml() } end end |
#to_plurimath(options = {}) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/unitsml/formula.rb', line 74 def to_plurimath( = {}) ensure_plurimath_defined! = () return Plurimath::Math.parse(to_asciimath(), :asciimath) if @orig_text.match?(/-$/) Plurimath::Math.parse(to_mathml(), :mathml) end |
#to_unicode(options = {}) ⇒ Object
59 60 61 |
# File 'lib/unitsml/formula.rb', line 59 def to_unicode( = {}) value.map { |obj| obj.to_unicode(()) }.join end |
#to_xml(options = {}) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/unitsml/formula.rb', line 63 def to_xml( = {}) = () if (dimensions_array = extract_dimensions(value)).any? dimensions(sort_dims(dimensions_array), ) elsif @orig_text.match(/-$/) prefixes() else units() end end |