Class: Tarantool::Util::AutoType

Inherits:
Object
  • Object
show all
Includes:
Comparable, Packer
Defined in:
lib/tarantool/util.rb

Constant Summary

Constants included from Packer

Packer::INT16, Packer::INT32, Packer::INT64, Packer::INT8, Packer::MAX_INT16, Packer::MAX_INT32, Packer::MAX_INT64, Packer::MAX_INT8, Packer::MAX_SINT16, Packer::MAX_SINT32, Packer::MAX_SINT64, Packer::MAX_SINT8, Packer::MIN_INT, Packer::MIN_SINT16, Packer::MIN_SINT32, Packer::MIN_SINT64, Packer::MIN_SINT8, Packer::SINT16, Packer::SINT32, Packer::SINT64, Packer::SINT8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ AutoType

Returns a new instance of AutoType.



57
58
59
# File 'lib/tarantool/util.rb', line 57

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly) Also known as: to_str, to_s

Returns the value of attribute data.



56
57
58
# File 'lib/tarantool/util.rb', line 56

def data
  @data
end

Instance Method Details

#%(oth) ⇒ Object



127
# File 'lib/tarantool/util.rb', line 127

def %(oth) to_i % oth end

#*(oth) ⇒ Object



125
# File 'lib/tarantool/util.rb', line 125

def *(oth) to_i * oth end

#**(oth) ⇒ Object



128
# File 'lib/tarantool/util.rb', line 128

def **(oth) to_i ** oth end

#+(oth) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/tarantool/util.rb', line 113

def +(oth)
  case oth
  when Numeric
    to_i + oth
  when String
    @data + oth
  when AutoType
    @data + oth.data
  end
end

#-(oth) ⇒ Object



124
# File 'lib/tarantool/util.rb', line 124

def -(oth) to_i - oth end

#/(oth) ⇒ Object



126
# File 'lib/tarantool/util.rb', line 126

def /(oth) to_i / oth end

#<=>(oth) ⇒ Object



102
103
104
105
106
107
108
109
110
111
# File 'lib/tarantool/util.rb', line 102

def <=>(oth)
  case oth
  when Numeric
    to_i <=> oth
  when String
    @data <=> oth
  when AutoType
    @data <=> oth.data
  end
end

#==(oth) ⇒ Object Also known as: eql?



90
91
92
93
94
95
96
97
98
99
# File 'lib/tarantool/util.rb', line 90

def ==(oth)
  case oth
  when Numeric
    to_i == oth
  when String
    @data == oth
  when AutoType
    @data == oth.data
  end
end

#bytesizeObject



131
# File 'lib/tarantool/util.rb', line 131

def bytesize; @data.bytesize  end

#coerce(oth) ⇒ Object



75
76
77
78
79
80
81
82
# File 'lib/tarantool/util.rb', line 75

def coerce(oth)
  case oth
  when Numeric
    [oth, to_i]
  when String
    [oth, @data]
  end
end

#empty?Boolean

Returns:

  • (Boolean)


130
# File 'lib/tarantool/util.rb', line 130

def empty?;   @data.empty?    end

#hashObject



134
# File 'lib/tarantool/util.rb', line 134

def hash;     @data.hash      end

#inspectObject



86
87
88
# File 'lib/tarantool/util.rb', line 86

def inspect
  "<#{self.class.name} data=#{@data.inspect}>"
end

#lengthObject



133
# File 'lib/tarantool/util.rb', line 133

def length;   @data.length    end

#sizeObject



132
# File 'lib/tarantool/util.rb', line 132

def size;     @data.size      end

#to_intObject Also known as: to_i



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/tarantool/util.rb', line 61

def to_int
  case @data.bytesize
  when 8
    ::BinUtils.get_int64_le(@data)
  when 4
    ::BinUtils.get_int32_le(@data)
  when 2
    ::BinUtils.get_int16_le(@data)
  else
    raise ValueError, "Bad field size #{field_size} for integer field ##{i}"
  end
end