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.



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

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.



984
985
986
# File 'lib/teradata-cli/connection.rb', line 984

def fractional
  @fractional
end

#widthObject (readonly)

Returns the value of attribute width.



983
984
985
# File 'lib/teradata-cli/connection.rb', line 983

def width
  @width
end

Instance Method Details

#get_binary_data(width) ⇒ Object



973
974
975
976
977
978
979
980
981
# File 'lib/teradata-cli/connection.rb', line 973

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



986
987
988
# File 'lib/teradata-cli/connection.rb', line 986

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