saturday 0.0.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/saturday/dates.rb +37 -6
  2. data/lib/saturday.rb +8 -4
  3. metadata +2 -2
@@ -1,12 +1,43 @@
1
1
  require 'date'
2
2
  class Saturday::Dates
3
- attr_accessor :date
3
+ attr_accessor :date ,:year ,:month
4
+
5
+ MONTHS_MAP = [{:january => 31},
6
+ {:february => 28},
7
+ {:march => 31},
8
+ {:april => 30},
9
+ {:may => 31},
10
+ {:june => 30},
11
+ {:july => 31},
12
+ {:august => 31},
13
+ {:september => 30},
14
+ {:october => 31},
15
+ {:november => 30},
16
+ {:december => 31}]
4
17
 
5
- def initialize(year,month,day)
6
- @date = Date.new(year,month,day)
18
+ def initialize(year=nil,month=nil)
19
+ @year = year
20
+ @month = month
21
+ @date = @year && @month.nil? ? Date.new(year) : Date.new(year,month)
7
22
  end
8
23
 
9
- def month
10
- @date.mon
11
- end
24
+ def find_saturdays
25
+ @date.leap? ? MONTHS_MAP[1][:february] = 29 : MONTHS_MAP
26
+ dates = []
27
+ year ,month = @date.year ,@date.month
28
+ if @year && @month
29
+ MONTHS_MAP[@month - 1].each_pair { |key,value| dates << find_dates(year,month,value)}
30
+ else
31
+ MONTHS_MAP.each {|k| k.each_pair { |key,value| dates << find_dates(year,MONTHS_MAP.index(k) + 1,value)} }
32
+ end
33
+ dates
34
+ end
35
+
36
+ private
37
+
38
+ def find_dates(year,month,value)
39
+ saturdays = []
40
+ 1.upto(value) {|o| saturdays << Date.new(year,month,o) if Date.new(year,month,o).saturday? }
41
+ saturdays
42
+ end
12
43
  end
data/lib/saturday.rb CHANGED
@@ -1,9 +1,13 @@
1
-
2
1
  class Saturday
3
- def self.dates(year,month,date)
4
- date = Dates.new(year,month,date)
5
- date.month
2
+ def self.by_year(year)
3
+ date=Dates.new(year)
4
+ date.find_saturdays
6
5
  end
7
6
 
7
+ def self.by_year_and_month(year,month)
8
+ date= Dates.new(year,month)
9
+ date.find_saturdays
10
+ end
11
+
8
12
  end
9
13
  require 'saturday/dates'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: saturday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -44,5 +44,5 @@ rubyforge_project:
44
44
  rubygems_version: 1.8.10
45
45
  signing_key:
46
46
  specification_version: 3
47
- summary: Saturday !
47
+ summary: Saturday helps you find Saturday's for a month/year or month-year!
48
48
  test_files: []