Class: Dates::Saturday

Inherits:
Object
  • Object
show all
Defined in:
lib/saturday/dates.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year = nil, month = nil) ⇒ Saturday

Returns a new instance of Saturday.



20
21
22
23
24
# File 'lib/saturday/dates.rb', line 20

def initialize(year=nil,month=nil)
  @year = year
  @month = month
  @date = @year && @month.nil? ? Date.new(year) : Date.new(year,month)
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



18
19
20
# File 'lib/saturday/dates.rb', line 18

def date
  @date
end

#monthObject

Returns the value of attribute month.



18
19
20
# File 'lib/saturday/dates.rb', line 18

def month
  @month
end

#yearObject

Returns the value of attribute year.



18
19
20
# File 'lib/saturday/dates.rb', line 18

def year
  @year
end

Instance Method Details

#find_saturdaysObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/saturday/dates.rb', line 26

def find_saturdays
  @date.leap? ? MONTHS_MAP[:feb] = 29 : MONTHS_MAP
  dates = []
  year ,month = @date.year ,@date.month
  if @year && @month
    MONTHS_MAP.each_with_index { |(key,value),index|  dates << find_dates(year,month,value) if month == index} 
 else
    MONTHS_MAP.each_with_index { |(key,value),index|  dates << find_dates(year,month = index,value) unless index==0}  
  end  
  dates
end