lib/arjdbc/postgresql/column.rb
def type_cast(value)
        return if value.nil?
        return super if encoded? # respond_to?(:encoded?) only since AR-3.2

        # NOTE: we do not use OID::Type
        # @oid_type.type_cast value

        return value if array? # handled on the connection (JDBC) side

        case type
        when :hstore then self.class.string_to_hstore value
        when :json then self.class.string_to_json value
        when :cidr, :inet then self.class.string_to_cidr value
        when :macaddr then value
        when :tsvector then value
        when :datetime, :timestamp then self.class.string_to_time value
        else
          case sql_type
          when 'money'
            # Because money output is formatted according to the locale, there
            # are two cases to consider (note the decimal separators) :
            # (1) $12,345,678.12
            # (2) $12.345.678,12
            case value
            when /^-?\D+[\d,]+\.\d{2}$/ # (1)
              value.gsub!(/[^-\d.]/, '')
            when /^-?\D+[\d.]+,\d{2}$/ # (2)
              value.gsub!(/[^-\d,]/, '')
              value.sub!(/,/, '.')
            end
            self.class.value_to_decimal value
          when /^point/
            value.is_a?(String) ? self.class.string_to_point(value) : value
          when /^(bit|varbit)/
            value.is_a?(String) ? self.class.string_to_bit(value) : value
          when /(.*?)range$/
            return if value.nil? || value == 'empty'
            return value if value.is_a?(::Range)

            extracted = extract_bounds(value)

            case $1 # subtype
            when 'date' # :date
              from = self.class.value_to_date(extracted[:from])
              from -= 1.day if extracted[:exclude_start]
              to = self.class.value_to_date(extracted[:to])
            when 'num' # :decimal
              from = BigDecimal.new(extracted[:from].to_s)
              # FIXME: add exclude start for ::Range, same for timestamp ranges
              to = BigDecimal.new(extracted[:to].to_s)
            when 'ts', 'tstz' # :time
              from = self.class.string_to_time(extracted[:from])
              to = self.class.string_to_time(extracted[:to])
            when 'int4', 'int8' # :integer
              from = to_integer(extracted[:from]) rescue value ? 1 : 0
              from -= 1 if extracted[:exclude_start]
              to = to_integer(extracted[:to]) rescue value ? 1 : 0
            else
              return value
            end

            ::Range.new(from, to, extracted[:exclude_end])
          else super
          end
        end
      end
# Casts value (which is a String) to an appropriate instance.
Casts value (which is a String) to an appropriate instance.
Casts value ( which is a String ) to an appropriate instance .
def type_cast(value)
        return if value.nil?
        return super if encoded? 
        return value if array? 
        case type
        when :hstore then self.class.string_to_hstore value
        when :json then self.class.string_to_json value
        when :cidr, :inet then self.class.string_to_cidr value
        when :macaddr then value
        when :tsvector then value
        when :datetime, :timestamp then self.class.string_to_time value
        else
          case sql_type
          when 'money'
            case value
            when /^-?\D+[\d,]+\.\d{2}$/ 
              value.gsub!(/[^-\d.]/, '')
            when /^-?\D+[\d.]+,\d{2}$/ 
              value.gsub!(/[^-\d,]/, '')
              value.sub!(/,/, '.')
            end
            self.class.value_to_decimal value
          when /^point/
            value.is_a?(String) ? self.class.string_to_point(value) : value
          when /^(bit|varbit)/
            value.is_a?(String) ? self.class.string_to_bit(value) : value
          when /(.*?)range$/
            return if value.nil? || value == 'empty'
            return value if value.is_a?(::Range)
            extracted = extract_bounds(value)
            case $1 
            when 'date' 
              from = self.class.value_to_date(extracted[:from])
              from -= 1.day if extracted[:exclude_start]
              to = self.class.value_to_date(extracted[:to])
            when 'num' 
              from = BigDecimal.new(extracted[:from].to_s)
              to = BigDecimal.new(extracted[:to].to_s)
            when 'ts', 'tstz' 
              from = self.class.string_to_time(extracted[:from])
              to = self.class.string_to_time(extracted[:to])
            when 'int4', 'int8' 
              from = to_integer(extracted[:from]) rescue value ? 1 : 0
              from -= 1 if extracted[:exclude_start]
              to = to_integer(extracted[:to]) rescue value ? 1 : 0
            else
              return value
            end
            ::Range.new(from, to, extracted[:exclude_end])
          else super
          end
        end
      end
def type_cast ( value ) return if value . nil? return super if encoded? return value if array? case type when :hstore then self . class . string_to_hstore value when :json then self . class . string_to_json value when :cidr , :inet then self . class . string_to_cidr value when :macaddr then value when :tsvector then value when :datetime , :timestamp then self . class . string_to_time value else case sql_type when 'money' case value when / ^-? \D +[ \d ,]+ \. \d {2}$ / value . gsub! ( / [^- \d .] / , '' ) when / ^-? \D +[ \d .]+, \d {2}$ / value . gsub! ( / [^- \d ,] / , '' ) value . sub! ( / , / , '.' ) end self . class . value_to_decimal value when / ^point / value . is_a? ( String ) ? self . class . string_to_point ( value ) : value when / ^(bit|varbit) / value . is_a? ( String ) ? self . class . string_to_bit ( value ) : value when / (.*?)range$ / return if value . nil? || value == 'empty' return value if value . is_a? ( :: Range ) extracted = extract_bounds ( value ) case $1 when 'date' from = self . class . value_to_date ( extracted [ :from ] ) from -= 1 . day if extracted [ :exclude_start ] to = self . class . value_to_date ( extracted [ :to ] ) when 'num' from = BigDecimal . new ( extracted [ :from ] . to_s ) to = BigDecimal . new ( extracted [ :to ] . to_s ) when 'ts' , 'tstz' from = self . class . string_to_time ( extracted [ :from ] ) to = self . class . string_to_time ( extracted [ :to ] ) when 'int4' , 'int8' from = to_integer ( extracted [ :from ] ) rescue value ? 1 : 0 from -= 1 if extracted [ :exclude_start ] to = to_integer ( extracted [ :to ] ) rescue value ? 1 : 0 else return value end :: Range . new ( from , to , extracted [ :exclude_end ] ) else super end end end
Casts value (which is a String) to an appropriate instance.
Casts value ( which is a String ) to an appropriate instance .
# respond_to?(:encoded?) only since AR-3.2 # NOTE: we do not use OID::Type # @oid_type.type_cast value # handled on the connection (JDBC) side # Because money output is formatted according to the locale, there # are two cases to consider (note the decimal separators) : # (1) $12,345,678.12 # (2) $12.345.678,12 # (1) # (2) # subtype # :date # :decimal # FIXME: add exclude start for ::Range, same for timestamp ranges # :time # :integer
value