Class: Informix::IntervalYTM
- Inherits:
-
IntervalBase
- Object
- IntervalBase
- Informix::IntervalYTM
- Defined in:
- lib/informix/interval.rb
Overview
The IntervalYTM
class is an Interval class dedicated only to represent intervals in the scope YEAR TO MONTH.
Instance Attribute Summary collapse
-
#months ⇒ Object
readonly
Returns the value of attribute months.
-
#years ⇒ Object
readonly
Returns the value of attribute years.
Attributes inherited from IntervalBase
Instance Method Summary collapse
-
#+(obj) ⇒ Object
interval + date => date interval + datetime => datetime.
-
#initialize(val) ⇒ IntervalYTM
constructor
Creates an IntervalYTM object with
val
as value. -
#to_months ⇒ Object
Converts invl to months.
-
#to_s ⇒ Object
Returns an ANSI SQL standards compliant string representation.
-
#to_years ⇒ Object
Converts a invl to years.
Methods inherited from IntervalBase
Constructor Details
#initialize(val) ⇒ IntervalYTM
Creates an IntervalYTM object with val
as value.
IntervalYTM.new(val) => interval
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/informix/interval.rb', line 106 def initialize(val) super @val = val.to_i @years, @months = @val.abs.divmod 12 if @val < 0 @years = -@years @months = -@months end @fields = [ @years, @months ] end |
Instance Attribute Details
#months ⇒ Object (readonly)
Returns the value of attribute months.
101 102 103 |
# File 'lib/informix/interval.rb', line 101 def months @months end |
#years ⇒ Object (readonly)
Returns the value of attribute years.
101 102 103 |
# File 'lib/informix/interval.rb', line 101 def years @years end |
Instance Method Details
#+(obj) ⇒ Object
interval + date => date
interval + datetime => datetime
119 120 121 122 123 124 125 126 |
# File 'lib/informix/interval.rb', line 119 def +(obj) case obj when Date, DateTime obj >> @val else super end end |
#to_months ⇒ Object
Converts invl to months
invl.to_months => numeric
141 |
# File 'lib/informix/interval.rb', line 141 def to_months; @val end |
#to_s ⇒ Object
Returns an ANSI SQL standards compliant string representation
invl.to_s => string
131 |
# File 'lib/informix/interval.rb', line 131 def to_s; "%d-%02d" % [@years, @months.abs] end |
#to_years ⇒ Object
Converts a invl to years
invl.to_years => numeric
136 |
# File 'lib/informix/interval.rb', line 136 def to_years; Rational === @val ? @val/12 : @val/12.0 end |