Class: Unitsml::Extender

Inherits:
Object
  • Object
show all
Defined in:
lib/unitsml/extender.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbol) ⇒ Extender

Returns a new instance of Extender.



7
8
9
# File 'lib/unitsml/extender.rb', line 7

def initialize(symbol)
  @symbol = symbol
end

Instance Attribute Details

#symbolObject

Returns the value of attribute symbol.



5
6
7
# File 'lib/unitsml/extender.rb', line 5

def symbol
  @symbol
end

Instance Method Details

#==(object) ⇒ Object



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

def ==(object)
  self.class == object.class &&
    symbol == object&.symbol
end

#to_asciimath(options) ⇒ Object



29
30
31
# File 'lib/unitsml/extender.rb', line 29

def to_asciimath(options)
  multiplier(options[:multiplier] || symbol)
end

#to_html(options) ⇒ Object



33
34
35
# File 'lib/unitsml/extender.rb', line 33

def to_html(options)
  multiplier(options[:multiplier] || "", unicode: true, html: true)
end

#to_latex(options) ⇒ Object



25
26
27
# File 'lib/unitsml/extender.rb', line 25

def to_latex(options)
  multiplier(options[:multiplier] || "/")
end

#to_mathml(options) ⇒ Object



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

def to_mathml(options)
  rspace = "thickmathspace" if options[:multiplier] == :space
  extender = multiplier(options[:multiplier] || "", unicode: true)
  {
    method_name: :mo,
    value: ::Mml::Mo.new(value: extender, rspace: rspace),
  }
end

#to_unicode(options) ⇒ Object



37
38
39
40
41
# File 'lib/unitsml/extender.rb', line 37

def to_unicode(options)
  extender = options[:multiplier] ||
               symbol == "*" ? "·" : symbol
  multiplier(extender)
end