Class: Unitsml::Fenced

Inherits:
Object
  • Object
show all
Includes:
FencedNumeric, MathmlHelper
Defined in:
lib/unitsml/fenced.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MathmlHelper

coerce_mml_v4_collection_attributes!, coerce_mml_v4_collection_value, mml_v4_class_for, mml_v4_content_attribute, mml_v4_context, mml_v4_from_xml, mml_v4_new, mml_v4_with_content

Methods included from FencedNumeric

#to_f, #to_i

Constructor Details

#initialize(open_paren, value, close_paren) ⇒ Fenced

Returns a new instance of Fenced.



10
11
12
13
14
# File 'lib/unitsml/fenced.rb', line 10

def initialize(open_paren, value, close_paren)
  @open_paren = open_paren
  @value = value
  @close_paren = close_paren
end

Instance Attribute Details

#close_parenObject (readonly)

Returns the value of attribute close_paren.



8
9
10
# File 'lib/unitsml/fenced.rb', line 8

def close_paren
  @close_paren
end

#open_parenObject (readonly)

Returns the value of attribute open_paren.



8
9
10
# File 'lib/unitsml/fenced.rb', line 8

def open_paren
  @open_paren
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/unitsml/fenced.rb', line 8

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
19
20
21
# File 'lib/unitsml/fenced.rb', line 16

def ==(other)
  self.class == other.class &&
    open_paren == other&.open_paren &&
    value == other&.value &&
    close_paren == other&.close_paren
end

#dimensions_extractionObject



71
72
73
74
75
76
77
78
# File 'lib/unitsml/fenced.rb', line 71

def dimensions_extraction
  case value
  when Dimension
    value
  when Formula, Fenced
    value.dimensions_extraction
  end
end

#float_to_displayObject



55
56
57
# File 'lib/unitsml/fenced.rb', line 55

def float_to_display
  value.float_to_display
end

#negative?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/unitsml/fenced.rb', line 47

def negative?
  value.negative?
end

#raw_valueObject



59
60
61
# File 'lib/unitsml/fenced.rb', line 59

def raw_value
  value.raw_value
end

#to_asciimath(options = {}) ⇒ Object



23
24
25
# File 'lib/unitsml/fenced.rb', line 23

def to_asciimath(options = {})
  fenced_conversion_for(lang: :asciimath, options: options)
end

#to_html(options = {}) ⇒ Object



63
64
65
# File 'lib/unitsml/fenced.rb', line 63

def to_html(options = {})
  fenced_conversion_for(lang: :html, options: options)
end

#to_latex(options = {}) ⇒ Object



27
28
29
# File 'lib/unitsml/fenced.rb', line 27

def to_latex(options = {})
  fenced_conversion_for(lang: :latex, options: options)
end

#to_mathml(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/unitsml/fenced.rb', line 31

def to_mathml(options = {})
  mathml = value.to_mathml(options)
  return mathml unless options[:explicit_parenthesis]

  fenced = mml_v4_new(
    :mrow,
    mo_value: [mml_v4_new(:mo, value: open_paren)],
  )
  fenced.ordered = true
  fenced.element_order ||= [xml_order_element("mo")]
  [mathml].flatten.each { |record| add_math_element(fenced, record) }
  fenced.mo_value << mml_v4_new(:mo, value: close_paren)
  fenced.element_order << xml_order_element("mo")
  { method_name: :mrow, value: fenced }
end

#to_unicode(options = {}) ⇒ Object



67
68
69
# File 'lib/unitsml/fenced.rb', line 67

def to_unicode(options = {})
  fenced_conversion_for(lang: :unicode, options: options)
end

#update_negative_signObject



51
52
53
# File 'lib/unitsml/fenced.rb', line 51

def update_negative_sign
  value.update_negative_sign
end