class Cassandra::Types::Duration

Attributes

days[R]

@private

months[R]

@private

nanos[R]

@private

Public Class Methods

cql_type() click to toggle source
   # File lib/cassandra/duration.rb
77 def self.cql_type
78   Type.new(@kind)
79 end
deserialize(bytestr) click to toggle source

Requirements for CustomData module

   # File lib/cassandra/duration.rb
82 def self.deserialize(bytestr)
83   buffer = Cassandra::Protocol::CqlByteBuffer.new.append(bytestr)
84   Cassandra::Types::Duration.new(buffer.read_signed_vint,buffer.read_signed_vint,buffer.read_signed_vint)
85 end
new(months, days, nanos) click to toggle source

@private

Calls superclass method
   # File lib/cassandra/duration.rb
31 def initialize(months, days, nanos)
32   super(:duration)
33   @months = months
34   @days = days
35   @nanos = nanos
36 end
type() click to toggle source
   # File lib/cassandra/duration.rb
87 def self.type
88   Cassandra::Types::Custom.new('org.apache.cassandra.db.marshal.DurationType')
89 end

Public Instance Methods

==(other)
Alias for: eql?
assert(value, message = nil, &block) click to toggle source
   # File lib/cassandra/duration.rb
50 def assert(value, message = nil, &block)
51   Util.assert_instance_of(Duration, value, message, &block)
52 end
eql?(other) click to toggle source
   # File lib/cassandra/duration.rb
68 def eql?(other)
69   other.is_a?(Duration) &&
70     @months == other.months &&
71     @days == other.days &&
72     @nanos == other.nanos
73 end
Also aliased as: ==
hash() click to toggle source
   # File lib/cassandra/duration.rb
58 def hash
59   @hash ||= begin
60     h = 17
61     h = 31 * h + @months.hash
62     h = 31 * h + @days.hash
63     h = 31 * h + @nanos.hash
64     h
65   end
66 end
new(*values) click to toggle source
   # File lib/cassandra/duration.rb
38 def new(*values)
39   Util.assert_size(3, values, "Duration type expects three values, #{values.size} were provided")
40   values.each { |v| Util.assert_type(Int, v) }
41   Util.assert (Util.encode_zigzag32(values[0]) < @@four_byte_max), "Months value must be a valid 32-bit integer"
42   Util.assert (Util.encode_zigzag32(values[1]) < @@four_byte_max), "Days value must be a valid 32-bit integer"
43   Util.assert (Util.encode_zigzag64(values[2]) < @@eight_byte_max), "Nanos value must be a valid 64-bit integer"
44   all_positive = values.all? {|i| i >= 0 }
45   all_negative = values.all? {|i| i <= 0 }
46   Util.assert (all_positive or all_negative), "Values in a duration must be uniformly positive or negative"
47   Duration.new *values
48 end
serialize() click to toggle source
   # File lib/cassandra/duration.rb
91 def serialize
92   rv = Cassandra::Protocol::CqlByteBuffer.new
93   rv.append_signed_vint32(@months)
94   rv.append_signed_vint32(@days)
95   rv.append_signed_vint64(@nanos)
96   rv
97 end
to_s() click to toggle source
   # File lib/cassandra/duration.rb
54 def to_s
55   "Duration: months => #{@months}, days => #{@days}, nanos => #{@nanos}"
56 end