Class: Lumberjack::Formatter::MultiplyFormatter
- Inherits:
-
Object
- Object
- Lumberjack::Formatter::MultiplyFormatter
- Defined in:
- lib/lumberjack/formatter/multiply_formatter.rb
Overview
This formatter can be used to multiply a numeric value by a specified multiplier and optionally round to a specified number of decimal places.
This is useful for unit conversions (e.g., converting seconds to milliseconds) or scaling values for display purposes. Non-numeric values are passed through unchanged.
Instance Method Summary collapse
-
#call(value) ⇒ Numeric, Object
Multiply a numeric value by the configured multiplier and optionally round.
-
#initialize(multiplier, decimals = nil) ⇒ MultiplyFormatter
constructor
A new instance of MultiplyFormatter.
Constructor Details
#initialize(multiplier, decimals = nil) ⇒ MultiplyFormatter
16 17 18 19 |
# File 'lib/lumberjack/formatter/multiply_formatter.rb', line 16 def initialize(multiplier, decimals = nil) @multiplier = multiplier @decimals = decimals end |
Instance Method Details
#call(value) ⇒ Numeric, Object
Multiply a numeric value by the configured multiplier and optionally round.
26 27 28 29 30 31 32 |
# File 'lib/lumberjack/formatter/multiply_formatter.rb', line 26 def call(value) return value unless value.is_a?(Numeric) value *= @multiplier value = value.round(@decimals) if @decimals value end |