123456789_123456789_123456789_123456789_123456789_

Class: PG::TextDecoder::Date

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: PG::SimpleDecoder
Defined in: lib/pg/text_decoder/date.rb

Overview

This is a decoder class for conversion of PostgreSQL date type to Ruby Date values.

As soon as this class is used, it requires the ruby standard library ‘date’.

Constant Summary

::PG::Coder - Inherited

FORMAT_ERROR_MASK, FORMAT_ERROR_TO_PARTIAL, FORMAT_ERROR_TO_RAISE, FORMAT_ERROR_TO_STRING, TIMESTAMP_APP_LOCAL, TIMESTAMP_APP_UTC, TIMESTAMP_DB_LOCAL, TIMESTAMP_DB_UTC

Class Method Summary

::PG::Coder - Inherited

.new

Create a new coder object based on the attribute Hash.

Instance Attribute Summary

::PG::Coder - Inherited

#flags

Get current bitwise OR-ed coder flags.

#flags=

Set coder specific bitwise OR-ed flags.

#format

The format code that is sent alongside with an encoded query parameter value.

#format=

Specifies the format code that is sent alongside with an encoded query parameter value.

#name

Name of the coder or the corresponding data type.

#oid

The type OID that is sent alongside with an encoded query parameter value.

#oid=

Specifies the type OID that is sent alongside with an encoded query parameter value.

Instance Method Summary

Constructor Details

This class inherits a constructor from PG::Coder

Instance Method Details

#decode(string, tuple = nil, field = nil)

[ GitHub ]

  
# File 'lib/pg/text_decoder/date.rb', line 12

def decode(string, tuple=nil, field=nil)
	if string =~ /\A(\d{4})-(\d\d)-(\d\d)\z/
		::Date.new $1.to_i, $2.to_i, $3.to_i
	else
		string
	end
end