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.



60
61
62
# File 'lib/tarantool/util.rb', line 60

def initialize(data)
  @data = data
end

Instance Attribute Details

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

Returns the value of attribute data.



59
60
61
# File 'lib/tarantool/util.rb', line 59

def data
  @data
end

Instance Method Details

#%(oth) ⇒ Object



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

def %(oth) to_i % oth end

#*(oth) ⇒ Object



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

def *(oth) to_i * oth end

#**(oth) ⇒ Object



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

def **(oth) to_i ** oth end

#+(oth) ⇒ Object



116
117
118
119
120
121
122
123
124
125
# File 'lib/tarantool/util.rb', line 116

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

#-(oth) ⇒ Object



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

def -(oth) to_i - oth end

#/(oth) ⇒ Object



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

def /(oth) to_i / oth end

#<=>(oth) ⇒ Object



105
106
107
108
109
110
111
112
113
114
# File 'lib/tarantool/util.rb', line 105

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?



93
94
95
96
97
98
99
100
101
102
# File 'lib/tarantool/util.rb', line 93

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

#bytesizeObject



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

def bytesize; @data.bytesize  end

#coerce(oth) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/tarantool/util.rb', line 78

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?;   @data.empty?    end

#hashObject



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

def hash;     @data.hash      end

#inspectObject



89
90
91
# File 'lib/tarantool/util.rb', line 89

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

#lengthObject



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

def length;   @data.length    end

#sizeObject



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

def size;     @data.size      end

#to_intObject Also known as: to_i



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/tarantool/util.rb', line 64

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