Class: Unitsml::Number
Instance Attribute Summary collapse
Instance Method Summary
collapse
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
#to_f, #to_i
Constructor Details
#initialize(value) ⇒ Number
Returns a new instance of Number.
11
12
13
|
# File 'lib/unitsml/number.rb', line 11
def initialize(value)
@value = value
end
|
Instance Attribute Details
#value ⇒ Object
Also known as:
raw_value
Returns the value of attribute value.
8
9
10
|
# File 'lib/unitsml/number.rb', line 8
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Object
15
16
17
18
|
# File 'lib/unitsml/number.rb', line 15
def ==(other)
self.class == other.class &&
value == other&.value
end
|
#float_to_display ⇒ Object
55
56
57
58
59
|
# File 'lib/unitsml/number.rb', line 55
def float_to_display
return "" if value.nil?
value.to_f.round(1).to_s.sub(/\.0$/, "")
end
|
#negative? ⇒ Boolean
43
44
45
|
# File 'lib/unitsml/number.rb', line 43
def negative?
value.start_with?("-")
end
|
#to_asciimath(_options) ⇒ Object
35
36
37
|
# File 'lib/unitsml/number.rb', line 35
def to_asciimath(_options)
value
end
|
#to_html(_options) ⇒ Object
27
28
29
|
# File 'lib/unitsml/number.rb', line 27
def to_html(_options)
value.sub("-", "−")
end
|
#to_latex(_options) ⇒ Object
31
32
33
|
# File 'lib/unitsml/number.rb', line 31
def to_latex(_options)
value
end
|
#to_mathml(_options) ⇒ Object
20
21
22
23
24
25
|
# File 'lib/unitsml/number.rb', line 20
def to_mathml(_options)
matched_value = value&.match(/-?(.+)/)
mn_value = matched_value ? matched_value[1] : value
mn_tag = mml_v4_new(:mn, value: mn_value)
value.start_with?("-") ? mrow_hash(mn_tag) : mn_hash(mn_tag)
end
|
#to_unicode(_options) ⇒ Object
39
40
41
|
# File 'lib/unitsml/number.rb', line 39
def to_unicode(_options)
value
end
|
#update_negative_sign ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/unitsml/number.rb', line 47
def update_negative_sign
self.value = if negative?
value.delete_prefix("-")
else
["-", value].join
end
end
|