Class: Unitsml::Number
- Inherits:
-
Object
- Object
- Unitsml::Number
- Includes:
- FencedNumeric
- Defined in:
- lib/unitsml/number.rb
Instance Attribute Summary collapse
-
#value ⇒ Object
(also: #raw_value)
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #float_to_display ⇒ Object
-
#initialize(value) ⇒ Number
constructor
A new instance of Number.
- #negative? ⇒ Boolean
- #to_asciimath(_options) ⇒ Object
- #to_html(_options) ⇒ Object
- #to_latex(_options) ⇒ Object
- #to_mathml(_options) ⇒ Object
- #to_unicode(_options) ⇒ Object
- #update_negative_sign ⇒ Object
Methods included from FencedNumeric
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
#value ⇒ Object 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_display ⇒ Object
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
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() value end |
#to_html(_options) ⇒ Object
26 27 28 |
# File 'lib/unitsml/number.rb', line 26 def to_html() value.sub("-", "−") end |
#to_latex(_options) ⇒ Object
30 31 32 |
# File 'lib/unitsml/number.rb', line 30 def to_latex() value end |
#to_mathml(_options) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/unitsml/number.rb', line 19 def to_mathml() 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() value end |
#update_negative_sign ⇒ Object
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 |