Class: DBI::Type::Boolean

Inherits:
Null
  • Object
show all
Defined in:
lib/dbi/types.rb

Overview

Represents a SQL BOOLEAN. Returns true/false. Falls back to Null.

Class Method Summary (collapse)

Class Method Details

+ (Object) parse(obj)



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/dbi/types.rb', line 187

def self.parse(obj)
    obj = super

    return nil if obj.nil?

    if obj == false or obj.kind_of? FalseClass
        return false
    elsif obj.kind_of? TrueClass
        return true
    else
        case obj
        when 't'
            return true
        when 'f'
            return false
        end

        if obj.respond_to? :to_i
            if obj.to_i == 0
                return false
            else
                return true
            end
        else
            # punt
            return nil
        end
    end
end