Class: Unitsml::Number

Inherits:
Object
  • Object
show all
Includes:
FencedNumeric
Defined in:
lib/unitsml/number.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FencedNumeric

#to_f, #to_i

Constructor Details

#initialize(value) ⇒ Number

Returns a new instance of Number.



10
11
12
# File 'lib/unitsml/number.rb', line 10

def initialize(value)
  @value = value
end

Instance Attribute Details

#valueObject Also known as: raw_value

Returns the value of attribute value.



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

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
17
# File 'lib/unitsml/number.rb', line 14

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

#float_to_displayObject



54
55
56
57
58
# File 'lib/unitsml/number.rb', line 54

def float_to_display
  return "" if value.nil?

  value.to_f.round(1).to_s.sub(/\.0$/, "")
end

#negative?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/unitsml/number.rb', line 42

def negative?
  value.start_with?("-")
end

#to_asciimath(_options) ⇒ Object



34
35
36
# File 'lib/unitsml/number.rb', line 34

def to_asciimath(_options)
  value
end

#to_html(_options) ⇒ Object



26
27
28
# File 'lib/unitsml/number.rb', line 26

def to_html(_options)
  value.sub("-", "−")
end

#to_latex(_options) ⇒ Object



30
31
32
# File 'lib/unitsml/number.rb', line 30

def to_latex(_options)
  value
end

#to_mathml(_options) ⇒ Object



19
20
21
22
23
24
# File 'lib/unitsml/number.rb', line 19

def to_mathml(_options)
  matched_value = value&.match(/-?(.+)/)
  mn_value = matched_value ? matched_value[1] : value
  mn_tag = ::Mml::V4::Mn.new(value: mn_value)
  value.start_with?("-") ? mrow_hash(mn_tag) : mn_hash(mn_tag)
end

#to_unicode(_options) ⇒ Object



38
39
40
# File 'lib/unitsml/number.rb', line 38

def to_unicode(_options)
  value
end

#update_negative_signObject



46
47
48
49
50
51
52
# File 'lib/unitsml/number.rb', line 46

def update_negative_sign
  self.value = if negative?
                 value.delete_prefix("-")
               else
                 ["-", value].join
               end
end