Class Informix::IntervalBase
In: lib/informix/interval.rb
Parent: Object

The IntervalBase class is used for sending and retrieving INTERVAL values to/from Informix.

It can be used in some expressions with Numeric, Date, DateTime and Time.

Methods

*   +   +@   -@   /   <=>   new   to_a  

Included Modules

Comparable

Attributes

val  [R] 

Public Class methods

IntervalBase.new(val) => interval

Creates an Interval object with val as value.

[Source]

    # File lib/informix/interval.rb, line 44
44:     def initialize(val)
45:       return @val = val if Numeric === val
46:       raise TypeError, "Expected Numeric" 
47:     end

Public Instance methods

Multiplies an Interval object by a Numeric

  interval*numeric  => interval

[Source]

    # File lib/informix/interval.rb, line 70
70:     def *(n)
71:       return self.class.new(@val*n) if Numeric === n
72:       raise TypeError, "Expected Numeric"
73:     end

Adds an Interval object to a Numeric or another compatible Interval

  interval + numeric  => interval
  interval + interval => interval

[Source]

    # File lib/informix/interval.rb, line 56
56:     def +(obj)
57:       case obj
58:       when Numeric
59:         self.class.new(@val + obj)
60:       when self.class
61:         self.class.new(@val + obj.val)
62:       else
63:         raise TypeError, "#{self.class} cannot be added to #{obj.class}"
64:       end
65:     end

[Source]

    # File lib/informix/interval.rb, line 49
49:     def +@; self end

[Source]

    # File lib/informix/interval.rb, line 50
50:     def -@; self.class.new(-@val) end

Divides an Interval object by a Numeric

  interval/numeric  => interval

[Source]

    # File lib/informix/interval.rb, line 78
78:     def /(n)
79:       return self.class.new(@val/n) if Numeric === n
80:       raise TypeError, "Expected Numeric"
81:     end

Compares two compatible Interval objects.

  interval1 <=> interval2  => true or false

[Source]

    # File lib/informix/interval.rb, line 86
86:     def <=>(ivl)
87:       return @val <=> ivl.val if self.class === ivl
88:       raise ArgumentError, "Incompatible qualifiers"
89:     end

Returns the fields of an Interval object as an Array

  invl.to_a   => array

[Source]

    # File lib/informix/interval.rb, line 94
94:     def to_a; @fields end

[Validate]