Sha256: 5d107fc9f73022ca3e64a4e18f96d6ecefd6ae9115fbaa6faadf4cc1d8894593

Contents?: true

Size: 529 Bytes

Versions: 12

Compression:

Stored size: 529 Bytes

Contents

module MongoModel
  module Types
    class Boolean < Object
      TRUE_VALUES = [ true, 'true', 't', 'TRUE', 'T', 'YES', 'y', '1', 1 ]
      FALSE_VALUES = [ false, 'false', 'f', 'FALSE', 'F', 'NO', 'n', '0', 0 ]
      
      def cast(value)
        if true?(value)
          true
        elsif false?(value)
          false
        end
      end
    
    private
      def true?(value)
        TRUE_VALUES.include?(value)
      end
      
      def false?(value)
        FALSE_VALUES.include?(value)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mongomodel-0.2.5 lib/mongomodel/support/types/boolean.rb
mongomodel-0.2.4 lib/mongomodel/support/types/boolean.rb
mongomodel-0.2.3 lib/mongomodel/support/types/boolean.rb
mongomodel-0.2.2 lib/mongomodel/support/types/boolean.rb
mongomodel-0.2.1 lib/mongomodel/support/types/boolean.rb
mongomodel-0.2.0 lib/mongomodel/support/types/boolean.rb
mongomodel-0.1.6 lib/mongomodel/support/types/boolean.rb
mongomodel-0.1.5 lib/mongomodel/support/types/boolean.rb
mongomodel-0.1.4 lib/mongomodel/support/types/boolean.rb
mongomodel-0.1.3 lib/mongomodel/support/types/boolean.rb
mongomodel-0.1.1 lib/mongomodel/support/types/boolean.rb
mongomodel-0.1 lib/mongomodel/support/types/boolean.rb