Sha256: e70dcc7f9d863e1bdedd1df146842dd7940bf06e9b1fd5a5a878d847779bb428

Contents?: true

Size: 595 Bytes

Versions: 30

Compression:

Stored size: 595 Bytes

Contents

module CassandraObject
  module Types
    class BooleanType < BaseType
      TRUE_VALS = [true, 'true', '1']
      FALSE_VALS = [false, 'false', '0', '', nil]
      VALID_VALS = TRUE_VALS + FALSE_VALS
      
      def encode(bool)
        unless VALID_VALS.include?(bool)
          raise ArgumentError.new("#{bool.inspect} is not a Boolean")
        end
        TRUE_VALS.include?(bool) ? '1' : '0'
      end

      def decode(str)
        raise ArgumentError.new("Cannot convert #{str} into a boolean") unless VALID_VALS.include?(str)
        TRUE_VALS.include?(str)
      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/boolean_type.rb
gotime-cassandra_object-4.5.0 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.4.5 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.4.4 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.4.3 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.4.0 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.3.2 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.3.1 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.3.0 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.2.2 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.2.0 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.1.0 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.0.2 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.0.1 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-4.0.0 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-3.0.5 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-3.0.4 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-3.0.3 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-3.0.2 lib/cassandra_object/types/boolean_type.rb
gotime-cassandra_object-3.0.1 lib/cassandra_object/types/boolean_type.rb