Class: Amalgalite::Boolean
- Inherits:
-
Object
- Object
- Amalgalite::Boolean
- Defined in:
- lib/amalgalite/boolean.rb
Overview
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 Method Summary collapse
-
.false_values ⇒ Object
list of downcased strings are potential false values.
-
.to_bool(val) ⇒ Object
Convert
val
to a string and attempt to convert it totrue
orfalse
. -
.true_values ⇒ Object
list of downcased strings are potential true values.
Class Method Details
.false_values ⇒ Object
list of downcased strings are potential false values
24 25 26 |
# File 'lib/amalgalite/boolean.rb', line 24 def false_values @false_values ||= %w[ false f no n 0 ] end |
.to_bool(val) ⇒ Object
Convert val
to a string and attempt to convert it to true
or false
31 32 33 34 35 36 37 38 39 |
# File 'lib/amalgalite/boolean.rb', line 31 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 |
.true_values ⇒ Object
list of downcased strings are potential true values
17 18 19 |
# File 'lib/amalgalite/boolean.rb', line 17 def true_values @true_values ||= %w[ true t yes y 1 ] end |