Class: DrLight::ScientificNumber::Formatter
- Inherits:
-
Object
- Object
- DrLight::ScientificNumber::Formatter
- Defined in:
- lib/dr_light/scientific_number/formatter.rb
Overview
Class responsible for formatting the values of DrLight::ScientificNumber
Instance Attribute Summary collapse
- #deviance ⇒ Object readonly
- #exponential ⇒ Object readonly
- #significant ⇒ Object readonly
- #value ⇒ Object readonly
Instance Method Summary collapse
-
#format_string ⇒ String
Returns the string of the format expected for #to_s.
-
#initialize(value:, deviance:) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(value:, deviance:) ⇒ Formatter
Returns a new instance of Formatter.
16 17 18 19 20 21 22 |
# File 'lib/dr_light/scientific_number/formatter.rb', line 16 def initialize(value:, deviance:) @value = value @deviance = deviance @significant = 1 @exponential = 0 format_value end |
Instance Attribute Details
#deviance ⇒ Object (readonly)
11 12 13 |
# File 'lib/dr_light/scientific_number/formatter.rb', line 11 def deviance @deviance end |
#exponential ⇒ Object (readonly)
11 12 13 |
# File 'lib/dr_light/scientific_number/formatter.rb', line 11 def exponential @exponential end |
#significant ⇒ Object (readonly)
11 12 13 |
# File 'lib/dr_light/scientific_number/formatter.rb', line 11 def significant @significant end |
#value ⇒ Object (readonly)
11 12 13 |
# File 'lib/dr_light/scientific_number/formatter.rb', line 11 def value @value end |
Instance Method Details
#format_string ⇒ String
Returns the string of the format expected for DrLight::ScientificNumber#to_s
28 29 30 31 32 33 |
# File 'lib/dr_light/scientific_number/formatter.rb', line 28 def format_string ["%<value>.#{significant}f"].tap do |values| values << '(%<deviance>d)' unless deviance.zero? values << 'e%<exponential>d' unless exponential.zero? end.join end |