class DCal::Year
Public Class Methods
new(value)
click to toggle source
# File lib/dcal/year.rb, line 5 def initialize(value) @value = value.to_i unless (1970..9999).cover? @value raise RangeError, "year #{@value} not in range 1970..9999" end end
Public Instance Methods
-(integer)
click to toggle source
# File lib/dcal/year.rb, line 31 def -(integer) to_i - integer end
<=>(other)
click to toggle source
# File lib/dcal/year.rb, line 23 def <=>(other) if other.integer? to_i <=> other else to_i <=> other.to_i end end
inspect()
click to toggle source
For better output in console
# File lib/dcal/year.rb, line 46 def inspect "#<#{self.class.name} #{to_s}>" end
leap?()
click to toggle source
# File lib/dcal/year.rb, line 13 def leap? # ref: http://en.wikipedia.org/wiki/Leap_year#Algorithm @value % 400 == 0 || (@value % 100 != 0 && @value % 4 == 0) end
leap_years_since_1970()
click to toggle source
# File lib/dcal/year.rb, line 18 def leap_years_since_1970 return 0 if @value == 1970 (1970...@value).select { |y| DCal::Year.new(y).leap? }.size end
to_i()
click to toggle source
For calculations
# File lib/dcal/year.rb, line 36 def to_i @value end
to_s()
click to toggle source
For inspect
# File lib/dcal/year.rb, line 41 def to_s @value.to_s end