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
-
#initialize(value = [], explicit_value: nil, root: false, orig_text: nil, norm_text: nil) ⇒ Formula
constructor
A new instance of Formula.
- #to_asciimath ⇒ Object
- #to_html ⇒ Object
- #to_latex ⇒ Object
- #to_mathml ⇒ Object
- #to_plurimath ⇒ Object
- #to_unicode ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(value = [], explicit_value: nil, root: false, orig_text: nil, norm_text: nil) ⇒ Formula
Returns a new instance of Formula.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/unitsml/formula.rb', line 9 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.
7 8 9 |
# File 'lib/unitsml/formula.rb', line 7 def explicit_value @explicit_value end |
#root ⇒ Object
Returns the value of attribute root.
7 8 9 |
# File 'lib/unitsml/formula.rb', line 7 def root @root end |
#value ⇒ Object
Returns the value of attribute value.
7 8 9 |
# File 'lib/unitsml/formula.rb', line 7 def value @value end |
Instance Method Details
#==(object) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/unitsml/formula.rb', line 21 def ==(object) self.class == object.class && value == object&.value && explicit_value == object&.explicit_value && root == object.root end |
#to_asciimath ⇒ Object
47 48 49 |
# File 'lib/unitsml/formula.rb', line 47 def to_asciimath value.map(&:to_asciimath).join end |
#to_html ⇒ Object
51 52 53 |
# File 'lib/unitsml/formula.rb', line 51 def to_html value.map(&:to_html).join end |
#to_latex ⇒ Object
43 44 45 |
# File 'lib/unitsml/formula.rb', line 43 def to_latex value.map(&:to_latex).join end |
#to_mathml ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/unitsml/formula.rb', line 28 def to_mathml if root attributes = { xmlns: "http://www.w3.org/1998/Math/MathML", display: "block" } math = Utility.ox_element("math", attributes: attributes) Ox.dump( Utility.update_nodes( math, value.map(&:to_mathml).flatten, ), ).gsub(/&(.*?)(?=<\/)/, '&\1') else value.map(&:to_mathml) end end |
#to_plurimath ⇒ Object
70 71 72 73 74 |
# File 'lib/unitsml/formula.rb', line 70 def to_plurimath return Plurimath::Math.parse(to_asciimath, :asciimath) if @orig_text.match?(/-$/) Plurimath::Math.parse(to_mathml, :mathml) end |
#to_unicode ⇒ Object
55 56 57 |
# File 'lib/unitsml/formula.rb', line 55 def to_unicode value.map(&:to_unicode).join end |
#to_xml ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/unitsml/formula.rb', line 59 def to_xml dimensions_array = extract_dimensions(value) if (dimensions_array).any? dimensions(sort_dims(dimensions_array)) elsif @orig_text.match(/-$/) prefixes else units end end |