Sha256: 84d1ea5d6bea4a44b8f6ebeadb88ce709ff4251e3b31fb9a7356fce26ecf5277

Contents?: true

Size: 470 Bytes

Versions: 13

Compression:

Stored size: 470 Bytes

Contents

module Superstore
  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)
      end

      def decode(str)
        TRUE_VALS.include?(str)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
superstore-2.4.4 lib/superstore/types/boolean_type.rb
superstore-2.4.3 lib/superstore/types/boolean_type.rb
superstore-2.4.2 lib/superstore/types/boolean_type.rb
superstore-2.4.1 lib/superstore/types/boolean_type.rb
superstore-2.4.0 lib/superstore/types/boolean_type.rb
superstore-2.3.0 lib/superstore/types/boolean_type.rb
superstore-2.2.0 lib/superstore/types/boolean_type.rb
superstore-2.1.3 lib/superstore/types/boolean_type.rb
superstore-2.1.2 lib/superstore/types/boolean_type.rb
superstore-2.1.1 lib/superstore/types/boolean_type.rb
superstore-2.1.0 lib/superstore/types/boolean_type.rb
superstore-2.0.1 lib/superstore/types/boolean_type.rb
superstore-2.0.0 lib/superstore/types/boolean_type.rb