Sha256: d2c68edb096142455215777f9446433bbfec1f7335d5cb937f8489fd647593e1

Contents?: true

Size: 478 Bytes

Versions: 11

Compression:

Stored size: 478 Bytes

Contents

module CassandraObject
  module Types
    class IntegerType
      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

11 entries across 11 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.5.0 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.4.2 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.4.1 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.4.0 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.3.6 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.3.5 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.3.4 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.3.3 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.3.2 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.3.1 lib/cassandra_object/types/integer_type.rb
gotime-cassandra_object-2.3.0 lib/cassandra_object/types/integer_type.rb