Sha256: 99b86b9d8eb6eb5f5c34a8b88e4a4167677ebc27a4dafd1488d03f8811e8d564

Contents?: true

Size: 481 Bytes

Versions: 18

Compression:

Stored size: 481 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) ? '1' : '0'
      end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
superstore-1.2.0 lib/superstore/types/boolean_type.rb
superstore-1.1.4 lib/superstore/types/boolean_type.rb
superstore-1.1.3 lib/superstore/types/boolean_type.rb
superstore-1.1.2 lib/superstore/types/boolean_type.rb
superstore-1.1.1 lib/superstore/types/boolean_type.rb
superstore-1.1.0 lib/superstore/types/boolean_type.rb
superstore-1.0.12 lib/superstore/types/boolean_type.rb
superstore-1.0.11 lib/superstore/types/boolean_type.rb
superstore-1.0.10 lib/superstore/types/boolean_type.rb
superstore-1.0.9 lib/superstore/types/boolean_type.rb
superstore-1.0.8 lib/superstore/types/boolean_type.rb
superstore-1.0.7 lib/superstore/types/boolean_type.rb
superstore-1.0.6 lib/superstore/types/boolean_type.rb
superstore-1.0.5 lib/superstore/types/boolean_type.rb
superstore-1.0.4 lib/superstore/types/boolean_type.rb
superstore-1.0.3 lib/superstore/types/boolean_type.rb
superstore-1.0.2 lib/superstore/types/boolean_type.rb
superstore-1.0.0 lib/superstore/types/boolean_type.rb