days_picker 1.0.3 → 1.1.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.
- data/lib/days_picker/constants.rb +15 -14
- data/lib/days_picker/dates.rb +32 -28
- data/lib/days_picker/helpers.rb +19 -108
- metadata +7 -7
@@ -1,17 +1,18 @@
|
|
1
1
|
module Constants
|
2
|
-
BY =
|
2
|
+
BY = %w(by_year by_year_and_month)
|
3
3
|
MONTHS_MAP = {:nil => :nil,
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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= %w(Sunday Monday Tuesday Wednesday Thursday Friday Saturday Weekday)
|
17
|
+
WEEKDAYS = %w(1 2 3 4 5)
|
17
18
|
end
|
data/lib/days_picker/dates.rb
CHANGED
@@ -4,36 +4,40 @@ require 'active_support/inflector'
|
|
4
4
|
|
5
5
|
module Dates
|
6
6
|
Constants::DAYS.each do |day|
|
7
|
-
|
8
|
-
|
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
|
7
|
+
Dates.const_set(day, Class.new do
|
8
|
+
attr_accessor :date ,:year ,:month
|
26
9
|
|
10
|
+
define_method (:initialize) do |*args|
|
11
|
+
@year = args[0]
|
12
|
+
@month = args[1]
|
13
|
+
@date = @year && @month.nil? ? Date.new(year) : Date.new(year,month)
|
14
|
+
end
|
27
15
|
|
28
|
-
|
16
|
+
define_method("find_#{day.downcase.pluralize}") do
|
17
|
+
@date.leap? ? Constants::MONTHS_MAP[:feb] = 29 : Constants::MONTHS_MAP
|
18
|
+
dates = Array.new
|
19
|
+
year ,month = @date.year ,@date.month
|
20
|
+
if @year && @month
|
21
|
+
Constants::MONTHS_MAP.each_with_index { |(key,value),index| dates << find_dates(year,month,value,day) if month == index}
|
22
|
+
else
|
23
|
+
Constants::MONTHS_MAP.each_with_index { |(key,value),index| dates << find_dates(year,month = index,value,day) unless index==0}
|
24
|
+
end
|
25
|
+
dates.flatten!
|
26
|
+
end
|
29
27
|
|
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
28
|
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
private
|
30
|
+
|
31
|
+
define_method(:find_dates) do |year,month,value,day|
|
32
|
+
dates = Array.new
|
33
|
+
1.upto(value) {|o| dates << Date.new(year,month,o) if day.eql?("Weekday") ? check_weekday(year,month,o): Date.new(year,month,o).send("#{day.downcase}?") }
|
34
|
+
dates.flatten
|
35
|
+
end
|
36
|
+
|
37
|
+
def check_weekday(*args)
|
38
|
+
Constants::WEEKDAYS.include?(Date.new(args[0],args[1],args[2]).wday.to_s)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
)
|
42
|
+
end
|
39
43
|
end
|
data/lib/days_picker/helpers.rb
CHANGED
@@ -1,112 +1,23 @@
|
|
1
1
|
module Helpers
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Constants::BY.each do |method|
|
21
|
-
define_method(method) do |year=nil,month=nil|
|
22
|
-
eval("Dates" + "::" + "Monday").new(year,month).send("find_mondays")
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
Constants::MONTHS_MAP.each_with_index do |(key,value),index|
|
27
|
-
define_method("in_#{key.to_s}") do |year=nil,month=nil|
|
28
|
-
eval("Dates" + "::" + "Monday").new(year,month = index).send("find_mondays")
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Tuesdays
|
35
|
-
class << self
|
36
|
-
Constants::BY.each do |method|
|
37
|
-
define_method(method) do |year=nil,month=nil|
|
38
|
-
eval("Dates" + "::" + "Tuesday").new(year,month).send("find_tuesdays")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
Constants::MONTHS_MAP.each_with_index do |(key,value),index|
|
43
|
-
define_method("in_#{key.to_s}") do |year=nil,month=nil|
|
44
|
-
eval("Dates" + "::" + "Tuesday").new(year,month = index).send("find_tuesdays")
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
class Wednesdays
|
50
|
-
class << self
|
51
|
-
Constants::BY.each do |method|
|
52
|
-
define_method(method) do |year=nil,month=nil|
|
53
|
-
eval("Dates" + "::" + "Wednesday").new(year,month).send("find_wednesdays")
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
Constants::MONTHS_MAP.each_with_index do |(key,value),index|
|
58
|
-
define_method("in_#{key.to_s}") do |year=nil,month=nil|
|
59
|
-
eval("Dates" + "::" + "Wednesday").new(year,month = index).send("find_wednesdays")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
class Thursdays
|
65
|
-
class << self
|
66
|
-
Constants::BY.each do |method|
|
67
|
-
define_method(method) do |year=nil,month=nil|
|
68
|
-
eval("Dates" + "::" + "Thursday").new(year,month).send("find_thursdays")
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
Constants::MONTHS_MAP.each_with_index do |(key,value),index|
|
73
|
-
define_method("in_#{key.to_s}") do |year=nil,month=nil|
|
74
|
-
eval("Dates" + "::" + "Thursday").new(year,month = index).send("find_thursdays")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
class Fridays
|
80
|
-
class << self
|
81
|
-
Constants::BY.each do |method|
|
82
|
-
define_method(method) do |year=nil,month=nil|
|
83
|
-
eval("Dates" + "::" + "Friday").new(year,month).send("find_fridays")
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
Constants::MONTHS_MAP.each_with_index do |(key,value),index|
|
88
|
-
define_method("in_#{key.to_s}") do |year=nil,month=nil|
|
89
|
-
eval("Dates" + "::" + "Friday").new(year,month = index).send("find_fridays")
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
class Saturdays
|
96
|
-
class << self
|
97
|
-
Constants::BY.each do |method|
|
98
|
-
define_method(method) do |year=nil,month=nil|
|
99
|
-
eval("Dates" + "::" + "Saturday").new(year,month).send("find_saturdays")
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
Constants::MONTHS_MAP.each_with_index do |(key,value),index|
|
104
|
-
define_method("in_#{key.to_s}") do |year=nil,month=nil|
|
105
|
-
eval("Dates" + "::" + "Saturday").new(year,month = index).send("find_saturdays")
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
2
|
+
Constants::DAYS.each do |day|
|
3
|
+
const_set(day.pluralize, Class.new do
|
4
|
+
class << self
|
5
|
+
Constants::BY.each do |method|
|
6
|
+
define_method(method) do |year=nil,month=nil|
|
7
|
+
klass_name = self.to_s.split("::").last
|
8
|
+
eval("Dates" + "::" + klass_name.singularize).new(year,month).send("find_#{klass_name.downcase}")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
Constants::MONTHS_MAP.each_with_index do |(key,value),index|
|
12
|
+
define_method("in_#{key.to_s}") do |year=nil,month=nil|
|
13
|
+
klass_name = self.to_s.split("::").last
|
14
|
+
eval("Dates" + "::" + klass_name.singularize).new(year,month = index).send("find_#{klass_name.downcase}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
)
|
110
20
|
end
|
21
|
+
end
|
111
22
|
|
112
23
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: days_picker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,9 +11,9 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2012-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: Days Picker helps you find the total Sundays, Mondays, Tuesdays,
|
15
|
-
Thursdays, Fridays and Saturdays of a Month or in a Year. (ie
|
16
|
-
,Saturdays.by_year(2012) .. )
|
14
|
+
description: Days Picker helps you find the total Weekdays, Sundays, Mondays, Tuesdays,
|
15
|
+
Wednesdays, Thursdays, Fridays and Saturdays of a Month or in a Year. (ie Weekdays.in_jan(2012),
|
16
|
+
Sundays.in_jan(2012) ,Saturdays.by_year(2012) .. )
|
17
17
|
email: ankit.gupta8898@gmail.com
|
18
18
|
executables:
|
19
19
|
- days_picker
|
@@ -48,7 +48,7 @@ rubyforge_project:
|
|
48
48
|
rubygems_version: 1.8.10
|
49
49
|
signing_key:
|
50
50
|
specification_version: 3
|
51
|
-
summary: Days Picker helps you find the total Sundays, Mondays, Tuesdays,
|
52
|
-
Thursdays, Fridays and Saturdays of a Month or in a Year. (ie
|
53
|
-
,Saturdays.by_year(2012) .. )
|
51
|
+
summary: Days Picker helps you find the total Weekdays, Sundays, Mondays, Tuesdays,
|
52
|
+
Wednesdays, Thursdays, Fridays and Saturdays of a Month or in a Year. (ie Weekdays.in_jan(2012),
|
53
|
+
Sundays.in_jan(2012) ,Saturdays.by_year(2012) .. )
|
54
54
|
test_files: []
|