Sha256: 571eaa724d0ac1240abee4eddd239dce8792c0ff1837647f5f68b229b1e39da2

Contents?: true

Size: 1.04 KB

Versions: 73

Compression:

Stored size: 1.04 KB

Contents

#--
# Copyright (c) 2008 Jeremy Hinegardner
# All rights reserved.  See LICENSE and/or COPYING for details.
#++
module Amalgalite
  ##
  # Do type conversion on values that could be boolen values into 
  # real 'true' or 'false'
  #
  # This is pulled from the possible boolean values from PostgreSQL
  #
  class Boolean
    class << self
      #
      # list of downcased strings are potential true values
      # 
      def true_values
        @true_values ||= %w[ true t yes y 1 ]
      end

      #
      # list of downcased strings are potential false values
      #
      def false_values
        @false_values ||= %w[ false f no n 0 ]
      end

      # 
      # Convert +val+ to a string and attempt to convert it to +true+ or +false+
      #
      def to_bool( val )
        return false if val.nil?
        unless defined? @to_bool
          @to_bool = {}
          true_values.each  { |t| @to_bool[t] = true  }
          false_values.each { |f| @to_bool[f] = false }
        end
        return @to_bool[val.to_s.downcase]
      end
    end
  end
end

Version data entries

73 entries across 73 versions & 2 rubygems

Version Path
amalgalite-1.6.3-x64-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.6.3 lib/amalgalite/boolean.rb
amalgalite-1.6.1-x86-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.6.1-x64-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.6.1 lib/amalgalite/boolean.rb
amalgalite-1.6.0-x64-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.6.0-x86-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.6.0 lib/amalgalite/boolean.rb
amalgalite-1.5.0-x86-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.5.0 lib/amalgalite/boolean.rb
amalgalite-1.4.1-x86-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.4.1 lib/amalgalite/boolean.rb
amalgalite-1.4.0-x86-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.4.0 lib/amalgalite/boolean.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/amalgalite-1.3.0/lib/amalgalite/boolean.rb
amalgalite-1.3.0-x86-mswin32 lib/amalgalite/boolean.rb
amalgalite-1.3.0 lib/amalgalite/boolean.rb
amalgalite-1.1.2-x86-mingw32 lib/amalgalite/boolean.rb
amalgalite-1.1.2-x86-mswin32 lib/amalgalite/boolean.rb
amalgalite-1.1.2 lib/amalgalite/boolean.rb