days_picker 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/days_picker ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'days_picker'
3
+ puts Saturdays.by_year(2011)
4
+ puts Sundays.by_year(2011)
@@ -0,0 +1,17 @@
1
+ module Constants
2
+ BY = ['by_year','by_year_and_month']
3
+ MONTHS_MAP = {:nil => :nil,
4
+ :jan => 31,
5
+ :feb => 28,
6
+ :mar => 31,
7
+ :apr => 30,
8
+ :may => 31,
9
+ :jun => 30,
10
+ :jul => 31,
11
+ :aug => 31,
12
+ :sep => 30,
13
+ :oct => 31,
14
+ :nov => 30,
15
+ :dec => 31}
16
+ DAYS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
17
+ end
@@ -0,0 +1,39 @@
1
+ require 'date'
2
+ require 'days_picker/constants'
3
+ require 'active_support/inflector'
4
+
5
+ module Dates
6
+ Constants::DAYS.each do |day|
7
+ Dates.const_set(day, Class.new do
8
+ attr_accessor :date ,:year ,:month
9
+ define_method (:initialize) do |year=nil,month=nil|
10
+ @year = year
11
+ @month = month
12
+ @date = @year && @month.nil? ? Date.new(year) : Date.new(year,month)
13
+ end
14
+
15
+ define_method("find_#{day.downcase.pluralize}") do
16
+ @date.leap? ? Constants::MONTHS_MAP[:feb] = 29 : Constants::MONTHS_MAP
17
+ dates = []
18
+ year ,month = @date.year ,@date.month
19
+ if @year && @month
20
+ Constants::MONTHS_MAP.each_with_index { |(key,value),index| dates << find_dates(year,month,value,day) if month == index}
21
+ else
22
+ Constants::MONTHS_MAP.each_with_index { |(key,value),index| dates << find_dates(year,month = index,value,day) unless index==0}
23
+ end
24
+ dates
25
+ end
26
+
27
+
28
+ private
29
+
30
+ define_method(:find_dates) do |year,month,value,day|
31
+ dates = Array.new
32
+ 1.upto(value) {|o| dates << Date.new(year,month,o) if Date.new(year,month,o).send("#{day.downcase}?") }
33
+ dates
34
+ end
35
+
36
+ end
37
+ )
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ require 'days_picker/dates'
3
+ require 'days_picker/helpers'
4
+ include Helpers
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: days_picker
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ankit gupta
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Days Picker helps you find the dates you want. Yoy can find Sundays
15
+ to Saturdays of a any Month by Year or by Month and Years
16
+ email: ankit.gupta8898@gmail.com
17
+ executables:
18
+ - days_picker
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/days_picker.rb
23
+ - lib/days_picker/dates.rb
24
+ - lib/days_picker/constants.rb
25
+ - bin/days_picker
26
+ homepage: https://github.com/ankit8898/days_picker
27
+ licenses: []
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 1.8.10
47
+ signing_key:
48
+ specification_version: 3
49
+ summary: Days Picker helps you find the dates you want. Yoy can find Sundays to Saturdays
50
+ of a Month or by Year or by Month years
51
+ test_files: []