Sha256: 85cfd16f70b112b623979a9ac299a185a8a2c26a1df0acaf506785e14c34102f

Contents?: true

Size: 489 Bytes

Versions: 48

Compression:

Stored size: 489 Bytes

Contents

module CassandraObject
  module Types
    class IntegerType < BaseType
      REGEX = /\A[-+]?\d+\Z/
      def encode(int)
        raise ArgumentError.new("#{self} requires an Integer. You passed #{int.inspect}") 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

48 entries across 48 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.11.7 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.6 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.5 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.4 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.3 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.2 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.1 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.11.0 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.11 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.10 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.9 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.8 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.7 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.6 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.5 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.4 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.3 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.2 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.1 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.10.0 lib/cassandra_object/types/integer_type.rb