Class: LensProtocol::OMA::Type::Numeric

Inherits:
Base
  • Object
show all
Defined in:
lib/lens_protocol/oma/type/numeric.rb

Instance Method Summary collapse

Methods inherited from Base

#format, #parse

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