Sha256: c86dca7c42282de43652004ef706d47f685a76f6f0f5317b73363fac65b4cc5a

Contents?: true

Size: 473 Bytes

Versions: 30

Compression:

Stored size: 473 Bytes

Contents

module CassandraObject
  module Types
    class FloatType < BaseType
      REGEX = /\A[-+]?\d+(\.\d+)?\Z/
      def encode(float)
        raise ArgumentError.new("#{float.inspect} is not a Float") unless float.kind_of?(Float)
        float.to_s
      end

      def decode(str)
        return nil if str.empty?
        raise ArgumentError.new("Cannot convert #{str} into a Float") unless str.kind_of?(String) && str.match(REGEX)
        str.to_f
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
gotime-cassandra_object-4.5.1 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.5.0 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.4.5 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.4.4 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.4.3 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.4.0 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.3.2 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.3.1 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.3.0 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.2.2 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.2.0 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.1.0 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.0.2 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.0.1 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-4.0.0 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-3.0.5 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-3.0.4 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-3.0.3 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-3.0.2 lib/cassandra_object/types/float_type.rb
gotime-cassandra_object-3.0.1 lib/cassandra_object/types/float_type.rb