Method: Cassandra::Types::Duration#new

Defined in:
lib/cassandra/duration.rb

#new(*values) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cassandra/duration.rb', line 38

def new(*values)
  Util.assert_size(3, values, "Duration type expects three values, #{values.size} were provided")
  values.each { |v| Util.assert_type(Int, v) }
  Util.assert (Util.encode_zigzag32(values[0]) < @@four_byte_max), "Months value must be a valid 32-bit integer"
  Util.assert (Util.encode_zigzag32(values[1]) < @@four_byte_max), "Days value must be a valid 32-bit integer"
  Util.assert (Util.encode_zigzag64(values[2]) < @@eight_byte_max), "Nanos value must be a valid 64-bit integer"
  all_positive = values.all? {|i| i >= 0 }
  all_negative = values.all? {|i| i <= 0 }
  Util.assert (all_positive or all_negative), "Values in a duration must be uniformly positive or negative"
  Duration.new *values
end