Sha256: 43f58c1b46d036f1165ed53c649cad3cc4e3d9313b59811648357bc029440bf3

Contents?: true

Size: 468 Bytes

Versions: 30

Compression:

Stored size: 468 Bytes

Contents

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

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

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
gotime-cassandra_object-3.0.0 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.13.0 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.12.5 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.12.4 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.12.3 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.12.2 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.12.1 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.12.0 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.9 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.8 lib/cassandra_object/types/integer_type.rb