Class: Informix::IntervalBase
- Inherits:
-
Object
- Object
- Informix::IntervalBase
- Includes:
- Comparable
- Defined in:
- lib/informix/interval.rb
Overview
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
.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#val ⇒ Object
readonly
Returns the value of attribute val.
Instance Method Summary collapse
-
#*(n) ⇒ Object
Multiplies an
Interval
object by aNumeric
. -
#+(obj) ⇒ Object
Adds an
Interval
object to aNumeric
or another compatibleInterval
. - #+@ ⇒ Object
- #-@ ⇒ Object
-
#/(n) ⇒ Object
Divides an
Interval
object by aNumeric
. -
#<=>(ivl) ⇒ Object
Compares two compatible
Interval
objects. -
#initialize(val) ⇒ IntervalBase
constructor
IntervalBase.new(val) => interval.
-
#to_a ⇒ Object
Returns the fields of an
Interval
object as anArray
.
Constructor Details
#initialize(val) ⇒ IntervalBase
IntervalBase.new(val) => interval
Creates an Interval
object with val
as value.
44 45 46 47 |
# File 'lib/informix/interval.rb', line 44 def initialize(val) return @val = val if Numeric === val raise TypeError, "Expected Numeric" end |
Instance Attribute Details
#val ⇒ Object (readonly)
Returns the value of attribute val.
39 40 41 |
# File 'lib/informix/interval.rb', line 39 def val @val end |
Instance Method Details
#*(n) ⇒ Object
Multiplies an Interval
object by a Numeric
interval*numeric => interval
70 71 72 73 |
# File 'lib/informix/interval.rb', line 70 def *(n) return self.class.new(@val*n) if Numeric === n raise TypeError, "Expected Numeric" end |
#+(obj) ⇒ Object
Adds an Interval
object to a Numeric
or another compatible Interval
interval + numeric => interval
interval + interval => interval
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/informix/interval.rb', line 56 def +(obj) case obj when Numeric self.class.new(@val + obj) when self.class self.class.new(@val + obj.val) else raise TypeError, "#{self.class} cannot be added to #{obj.class}" end end |
#+@ ⇒ Object
49 |
# File 'lib/informix/interval.rb', line 49 def +@; self end |
#-@ ⇒ Object
50 |
# File 'lib/informix/interval.rb', line 50 def -@; self.class.new(-@val) end |
#/(n) ⇒ Object
Divides an Interval
object by a Numeric
interval/numeric => interval
78 79 80 81 |
# File 'lib/informix/interval.rb', line 78 def /(n) return self.class.new(@val/n) if Numeric === n raise TypeError, "Expected Numeric" end |
#<=>(ivl) ⇒ Object
Compares two compatible Interval
objects.
interval1 <=> interval2 => true or false
86 87 88 89 |
# File 'lib/informix/interval.rb', line 86 def <=>(ivl) return @val <=> ivl.val if self.class === ivl raise ArgumentError, "Incompatible qualifiers" end |
#to_a ⇒ Object
Returns the fields of an Interval
object as an Array
invl.to_a => array
94 |
# File 'lib/informix/interval.rb', line 94 def to_a; @fields end |