Sha256: a34a983f4497ed22aaee82eaba25ac444cb2c1b00fbf594a4035fed0406344f1

Contents?: true

Size: 453 Bytes

Versions: 4

Compression:

Stored size: 453 Bytes

Contents

module LensProtocol
  module OMA
    module Type
      class Numeric < Base
        def initialize decimals: nil, **opts
          super **opts
          @decimals = decimals
        end

        def parse_value value
          Float(value) rescue nil
        end

        def format_value value
          if value && @decimals
            "%.#{@decimals}f" % value
          else
            value
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lens_protocol-0.1.3 lib/lens_protocol/oma/type/numeric.rb
lens_protocol-0.1.2 lib/lens_protocol/oma/type/numeric.rb
lens_protocol-0.1.1 lib/lens_protocol/oma/type/numeric.rb
lens_protocol-0.1.0 lib/lens_protocol/oma/type/numeric.rb