Class: TeradataCli::DecimalType

Inherits:
FieldType show all
Defined in:
lib/teradata-cli/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.



958
959
960
961
962
# File 'lib/teradata-cli/connection.rb', line 958

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.



975
976
977
# File 'lib/teradata-cli/connection.rb', line 975

def fractional
  @fractional
end

#widthObject (readonly)

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#get_binary_data(width) ⇒ Object



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

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



977
978
979
# File 'lib/teradata-cli/connection.rb', line 977

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