Class: Teradata::DecimalType

Inherits:
FieldType show all
Defined in:
lib/teradata/connection.rb

Instance Attribute Summary collapse

Attributes inherited from FieldType

#format, #name, #title, #type_code, #type_name

Instance Method Summary collapse

Methods inherited from FieldType

code_names, codes, create, #inspect, #to_s

Constructor Details

#initialize(type_name, type_code, len, name, format, title, extractor) ⇒ DecimalType

Returns a new instance of DecimalType.



957
958
959
960
961
# File 'lib/teradata/connection.rb', line 957

def initialize(type_name, type_code, len, name, format, title, extractor)
  super
  @width, @fractional = len.divmod(256)
  @length, @template = get_binary_data(@width)
end

Instance Attribute Details

#fractionalObject (readonly)

Returns the value of attribute fractional.



974
975
976
# File 'lib/teradata/connection.rb', line 974

def fractional
  @fractional
end

#widthObject (readonly)

Returns the value of attribute width.



973
974
975
# File 'lib/teradata/connection.rb', line 973

def width
  @width
end

Instance Method Details

#get_binary_data(width) ⇒ Object



963
964
965
966
967
968
969
970
971
# File 'lib/teradata/connection.rb', line 963

def get_binary_data(width)
  case
  when width <=  2 then return 1, 'c'
  when width <=  4 then return 2, 's'
  when width <=  9 then return 4, 'l'
  when width <= 18 then return 8, 'q'
  else return 16, nil
  end
end

#unmarshal(f) ⇒ Object



976
977
978
# File 'lib/teradata/connection.rb', line 976

def unmarshal(f)
  insert_fp(read_base_int(f).to_s, @fractional)
end