Class: LensProtocol::OMA::Type::Numeric
- Defined in:
- lib/lens_protocol/oma/type/numeric.rb
Instance Method Summary collapse
- #format_value(value) ⇒ Object
-
#initialize(decimals: nil, **opts) ⇒ Numeric
constructor
A new instance of Numeric.
- #parse_value(value) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(decimals: nil, **opts) ⇒ Numeric
Returns a new instance of Numeric.
5 6 7 8 |
# File 'lib/lens_protocol/oma/type/numeric.rb', line 5 def initialize decimals: nil, **opts super **opts @decimals = decimals end |
Instance Method Details
#format_value(value) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/lens_protocol/oma/type/numeric.rb', line 14 def format_value value if value && @decimals "%.#{@decimals}f" % value else value end end |
#parse_value(value) ⇒ Object
10 11 12 |
# File 'lib/lens_protocol/oma/type/numeric.rb', line 10 def parse_value value Float(value) rescue nil end |