Class: Vertica::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/vertica/column.rb

Constant Summary collapse

STRING_CONVERTER =
String.new.respond_to?(:force_encoding) ? lambda { |s| s.force_encoding('utf-8') } : nil
DATA_TYPE_CONVERSIONS =
[
  [:unspecified,  nil],
  [:tuple,        nil],
  [:pos,          nil],
  [:record,       nil],
  [:unknown,      nil],
  [:bool,         lambda { |s| s == 't' }],
  [:integer,      lambda { |s| s.to_i }],
  [:float,        lambda { |s| s.to_f }],
  [:char,         STRING_CONVERTER],
  [:varchar,      STRING_CONVERTER],
  [:date,         lambda { |s| Date.new(*s.split("-").map{|x| x.to_i}) }],
  [:time,         nil],
  [:timestamp,    lambda { |s| DateTime.parse(s, true) }],
  [:timestamp_tz, lambda { |s| DateTime.parse(s, true) }],
  [:interval,     nil],
  [:time_tz,      nil],
  [:numeric,      lambda { |s| BigDecimal.new(s) }],
  [:bytea,        nil],
  [:rle_tuple,    nil]
]
DATA_TYPES =
DATA_TYPE_CONVERSIONS.map { |t| t[0] }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(col) ⇒ Column

Returns a new instance of Column.



35
36
37
38
39
40
41
42
43
44
# File 'lib/vertica/column.rb', line 35

def initialize(col)
  @type_modifier    = col[:type_modifier]
  @format           = col[:format_code] == 0 ? :text : :binary
  @table_oid        = col[:table_oid]
  @name             = col[:name].to_sym
  @attribute_number = col[:attribute_number]
  @data_type        = DATA_TYPE_CONVERSIONS[col[:data_type_oid]][0]
  @converter        = DATA_TYPE_CONVERSIONS[col[:data_type_oid]][1]
  @size             = col[:data_type_size]
end

Instance Attribute Details

#data_typeObject (readonly)

Returns the value of attribute data_type.



7
8
9
# File 'lib/vertica/column.rb', line 7

def data_type
  @data_type
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/vertica/column.rb', line 3

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.



6
7
8
# File 'lib/vertica/column.rb', line 6

def size
  @size
end

#table_oidObject (readonly)

Returns the value of attribute table_oid.



4
5
6
# File 'lib/vertica/column.rb', line 4

def table_oid
  @table_oid
end

#type_modifierObject (readonly)

Returns the value of attribute type_modifier.



5
6
7
# File 'lib/vertica/column.rb', line 5

def type_modifier
  @type_modifier
end

Instance Method Details

#convert(s) ⇒ Object



46
47
48
49
# File 'lib/vertica/column.rb', line 46

def convert(s)
  return unless s
  @converter ? @converter.call(s) : s
end