Class: DrLight::ScientificNumber
- Inherits:
-
Object
- Object
- DrLight::ScientificNumber
- Defined in:
- lib/dr_light/scientific_number.rb,
lib/dr_light/scientific_number/formatter.rb,
lib/dr_light/scientific_number/normalizer.rb,
lib/dr_light/scientific_number/deviance_distance.rb
Overview
Number to be exibed in scientific number
Defined Under Namespace
Classes: DevianceDistance, Formatter, Normalizer
Instance Attribute Summary collapse
-
#deviance ⇒ Numeric
readonly
The deviance from the average (imprecision).
-
#value ⇒ Numeric
readonly
The number value (average).
Instance Method Summary collapse
-
#deviance_distance(other) ⇒ Float
Calculates the distance to another number in deviances.
-
#initialize(value, deviance = nil) ⇒ ScientificNumber
constructor
A new instance of ScientificNumber.
-
#to_s ⇒ String
string representation of number.
Constructor Details
#initialize(value, deviance = nil) ⇒ ScientificNumber
Returns a new instance of ScientificNumber.
32 33 34 35 |
# File 'lib/dr_light/scientific_number.rb', line 32 def initialize(value, deviance = nil) @value = value.to_f @deviance = deviance.to_f end |
Instance Attribute Details
#deviance ⇒ Numeric (readonly)
The deviance from the average (imprecision)
23 24 25 |
# File 'lib/dr_light/scientific_number.rb', line 23 def deviance @deviance end |
#value ⇒ Numeric (readonly)
The number value (average)
16 17 18 |
# File 'lib/dr_light/scientific_number.rb', line 16 def value @value end |
Instance Method Details
#deviance_distance(other) ⇒ Float
Calculates the distance to another number in deviances
the deviance will be a composition of both numbers deviances
72 73 74 |
# File 'lib/dr_light/scientific_number.rb', line 72 def deviance_distance(other) DevianceDistance.new(self, other).to_f end |
#to_s ⇒ String
string representation of number
44 45 46 47 48 49 50 51 |
# File 'lib/dr_light/scientific_number.rb', line 44 def to_s format( formatter.format_string, value: normalizer.value, exponential: normalizer.exponential, deviance: normalizer.deviance ) end |