Sha256: bd51959a975b6ae87f47fd0f36e4451d8d243bca6386bd0bdb0b29b3835f94e7

Contents?: true

Size: 622 Bytes

Versions: 14

Compression:

Stored size: 622 Bytes

Contents

module Rasti
  class Form
    module Types
      class Float
        class << self

          include Castable

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

          def valid?(value)
            !value.nil? && (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
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rasti-form-3.1.2 lib/rasti/form/types/float.rb
rasti-form-3.1.1 lib/rasti/form/types/float.rb
rasti-form-3.1.0 lib/rasti/form/types/float.rb
rasti-form-3.0.0 lib/rasti/form/types/float.rb
rasti-form-2.2.0 lib/rasti/form/types/float.rb
rasti-form-2.1.0 lib/rasti/form/types/float.rb
rasti-form-2.0.0 lib/rasti/form/types/float.rb
rasti-form-1.1.1 lib/rasti/form/types/float.rb
rasti-form-1.1.0 lib/rasti/form/types/float.rb
rasti-form-1.0.3 lib/rasti/form/types/float.rb
rasti-form-1.0.2 lib/rasti/form/types/float.rb
rasti-form-1.0.1 lib/rasti/form/types/float.rb
rasti-form-1.0.0 lib/rasti/form/types/float.rb
rasti-form-0.1.0 lib/rasti/form/types/float.rb