Class: Vertica::Column
- Inherits:
-
Object
- Object
- Vertica::Column
- 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
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#table_oid ⇒ Object
readonly
Returns the value of attribute table_oid.
-
#type_modifier ⇒ Object
readonly
Returns the value of attribute type_modifier.
Instance Method Summary collapse
- #convert(s) ⇒ Object
-
#initialize(col) ⇒ Column
constructor
A new instance of Column.
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_type ⇒ Object (readonly)
Returns the value of attribute data_type.
7 8 9 |
# File 'lib/vertica/column.rb', line 7 def data_type @data_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/vertica/column.rb', line 3 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/vertica/column.rb', line 6 def size @size end |
#table_oid ⇒ Object (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_modifier ⇒ Object (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 |