Class: Lumberjack::Formatter::RoundFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::RoundFormatter
- Defined in:
- lib/lumberjack/formatter/round_formatter.rb
Overview
Round numeric values to a set number of decimal places. This is useful when logging floating point numbers to reduce noise and rounding errors in the logs.
The formatter only affects numeric values, leaving other object types unchanged. This makes it safe to use as a general-purpose formatter for attributes that might contain various data types.
Instance Method Summary collapse
-
#call(obj) ⇒ Numeric, Object
Round a numeric value to the configured precision.
-
#initialize(precision = 3) ⇒ RoundFormatter
constructor
A new instance of RoundFormatter.
Constructor Details
#initialize(precision = 3) ⇒ RoundFormatter
Returns a new instance of RoundFormatter.
15 16 17 |
# File 'lib/lumberjack/formatter/round_formatter.rb', line 15 def initialize(precision = 3) @precision = precision end |
Instance Method Details
#call(obj) ⇒ Numeric, Object
Round a numeric value to the configured precision.
24 25 26 27 28 29 30 |
# File 'lib/lumberjack/formatter/round_formatter.rb', line 24 def call(obj) if obj.is_a?(Numeric) obj.round(@precision) else obj end end |