Sha256: 7851fbce6eabad408616532c14ac47ad02cb8b6cb5597d858122e9f6d34171ef

Contents?: true

Size: 536 Bytes

Versions: 2

Compression:

Stored size: 536 Bytes

Contents

module Rasti
  module Types
    class Float
      class << self

        include Castable

        FORMAT = /^(\d+\.)?\d+$/

        private

        def valid?(value)
          valid_string?(value) || transformable?(value)
        end

        def transform(value)
          value.to_f
        end

        def valid_string?(value)
          value.is_a?(::String) && value.match(FORMAT)
        end

        def transformable?(value)
          !value.is_a?(::String) && value.respond_to?(:to_f)
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rasti-types-2.0.1 lib/rasti/types/float.rb
rasti-types-2.0.0 lib/rasti/types/float.rb