week_of_month 1.2.3.1 → 1.2.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb8e17155b66f00d79619774220611769249f90d
4
- data.tar.gz: de433fd66043692ee66d04705ec26beec126d91f
3
+ metadata.gz: bb763a374f81af6d9930c901028abc73b85fdc17
4
+ data.tar.gz: 006949252e68ebb482b07254d031e5366671b264
5
5
  SHA512:
6
- metadata.gz: 481f139413ab807b87057c916aa09f4f19eea12745cd42058c2395fadc1b28d83fbf7c73de48de71bb18b20eb4ead9111c9ebd8fa7c051dead44c1390d44c26a
7
- data.tar.gz: e487771ab29e5c6cb351e70a634e83e6f20c37d2e76f0c4f0bbf18107814c6ad534d63cabbba9dc2aa4a282fc258a7291c9bbec66f647899854ac11b882c9bd5
6
+ metadata.gz: 695d2c55e137bc75e04f343cedf771569dc57ceda2112e7b20e48b7c399f3adf2bfea0d0949bcbe05d52d1d3c51e2951a6776f9c84f6f97c3084c8cf8691f0c9
7
+ data.tar.gz: a6a127b55d61f32cf2ccb83e7d6e12720479de5ece65e460a1ca8fba9545bab36183be2fac724d76ab61cc8499988401b5fabceae59f85a4795cbb93994c1a09
@@ -0,0 +1,7 @@
1
+ # Logfile created on 2014-04-28 22:41:29 +0530 by logger.rb/36483
2
+ I, [2014-04-28T22:41:29.237110 #16389] INFO -- : 0: rake (10.1.0) from /home/sachin/.rvm/gems/ruby-2.0.0-p247@global/specifications/rake-10.1.0.gemspec
3
+ I, [2014-04-28T22:41:29.266843 #16389] INFO -- : 0: week_of_month (1.2.3.1) from /home/sachin/projects/week-of-month/week_of_month.gemspec
4
+ I, [2014-04-28T22:41:29.267622 #16389] INFO -- : 0: bundler (1.5.0) from /home/sachin/.rvm/gems/ruby-2.0.0-p247@todo/specifications/bundler-1.5.0.gemspec
5
+ I, [2014-04-28T23:06:54.580647 #16882] INFO -- : 0: rake (10.1.0) from /home/sachin/.rvm/gems/ruby-2.0.0-p247@global/specifications/rake-10.1.0.gemspec
6
+ I, [2014-04-28T23:06:54.581035 #16882] INFO -- : 0: bundler (1.5.0) from /home/sachin/.rvm/gems/ruby-2.0.0-p247@todo/specifications/bundler-1.5.0.gemspec
7
+ I, [2014-04-28T23:06:54.596977 #16882] INFO -- : 0: week_of_month (1.2.3.1) from /home/sachin/projects/week-of-month/week_of_month.gemspec
data/.gitignore CHANGED
@@ -13,7 +13,7 @@ nbproject/
13
13
  *.swp
14
14
 
15
15
  # IDEA / RUBYMINE
16
- .idea
16
+ .idea/
17
17
 
18
18
  ## PROJECT::GENERAL
19
19
  tags
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem "rake"
3
+ gemspec
4
4
 
data/Gemfile.lock CHANGED
@@ -1,3 +1,8 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ week_of_month (1.2.3.2)
5
+
1
6
  GEM
2
7
  remote: https://rubygems.org/
3
8
  specs:
@@ -7,4 +12,6 @@ PLATFORMS
7
12
  ruby
8
13
 
9
14
  DEPENDENCIES
10
- rake
15
+ bundler (>= 1.0)
16
+ rake (>= 10.1.0)
17
+ week_of_month!
data/README.md ADDED
@@ -0,0 +1,182 @@
1
+ # Week of month
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/week_of_month.svg)][gem]
4
+ [![Climate](https://codeclimate.com/github/sachin87/week-of-month.png)][climate]
5
+ [![License](http://img.shields.io/license/MIT.png?color=green)][license]
6
+
7
+ [gem]: http://badge.fury.io/rb/week_of_month
8
+ [climate]: https://codeclimate.com/github/sachin87/week-of-month
9
+ [license]: http://opensource.org/licenses/MIT
10
+
11
+ Week of month is a gem which gives you access to methods for the Date and Time class objects. Among accurately displaying the days of a week in the form of a calendar arrangement, this gem will also provide you with tools for identifying which week of the month a particular date lies.
12
+
13
+ ## Getting Started
14
+
15
+ Week of month is released as a Ruby Gem. The gem is to be installed within a Ruby
16
+ or Rails application. To install, simply add the following to your Gemfile:
17
+
18
+ ```ruby
19
+ gem 'week_of_month'
20
+ ```
21
+
22
+ Run bundle install and don't forget to restart your server after you install a new gem.
23
+
24
+ You can also install this gem from the command line as:
25
+
26
+ ```ruby
27
+ gem install 'week_of_month'
28
+ ```
29
+ ## Assumption
30
+
31
+ Sunday is the first day of the week.
32
+
33
+ ## Usage
34
+
35
+ **Return the days of the month as if they were displayed on a calendar. In this example, the first day of January starts on a Sunday. Note the format is always (year, month, day)**
36
+
37
+ ```ruby
38
+ Date.new(2012,1,1).week_split
39
+
40
+ =begin
41
+ [[1, 2, 3, 4, 5, 6, 7],
42
+ [8, 9, 10, 11, 12, 13, 14],
43
+ [15, 16, 17, 18, 19, 20, 21],
44
+ [22, 23, 24, 25, 26, 27, 28],
45
+ [29, 30, 31]]
46
+ =end
47
+ ```
48
+ **Return the total number of weeks in a month.**
49
+
50
+ ```ruby
51
+ Date.new(2012,1,31).total_weeks
52
+ # => 5
53
+ ```
54
+
55
+ **Return what number week in the month a specific date lies. Can also return the number in english.**
56
+
57
+ ```ruby
58
+ Date.new(2012,1,31).week_of_month
59
+ # => 5
60
+
61
+ Date.new(2012,1,31).week_of_month_in_eng
62
+ # => "Fifth"
63
+ ```
64
+
65
+ **Return true if date lies in first week of month, otherwise false will be returned. Also works with second week and last week.**
66
+
67
+ ```ruby
68
+ Date.new(2012,1,1).first_week?
69
+ # => true
70
+
71
+ Date.new(2012,1,9).second_week?
72
+ # => true
73
+
74
+ Date.new(2012,1,31).last_week?
75
+ # => true
76
+ ```
77
+
78
+ **Returns the month for the specified date.**
79
+
80
+ ```ruby
81
+ Date.new(2012,1,1).name_of_month
82
+ # => "January"
83
+ ```
84
+
85
+ **Return true if date lies in the month of which the method is called, otherwise false will be returned (works for all months).**
86
+
87
+ ```ruby
88
+ Date.new(2012,1,1).january?
89
+ # => true
90
+
91
+ Date.new(2012,1,9).august?
92
+ # => false
93
+
94
+ Date.new(2012,12,25).december?
95
+ # => true
96
+ ```
97
+
98
+ **Return the number of days in a given month (regardless of selected day).**
99
+
100
+ ```ruby
101
+ Date.new(2012,1,1).last_day_of_month
102
+ # => 31
103
+
104
+ Date.new(2012,2,9).last_day_of_month
105
+ # => 29
106
+ ```
107
+
108
+ **Return the dates for which the day of the method falls (works for all days).**
109
+
110
+ ```ruby
111
+ Date.new(2012,1,1).all_mondays_in_month
112
+ # => [2, 9, 16, 23, 30]
113
+ ```
114
+
115
+ **Return the day of the week for the specified date.**
116
+
117
+ ```ruby
118
+ Date.new(2012,1,1).name_of_week_day
119
+ # => "Sunday"
120
+ ```
121
+
122
+ **Returns true if date falls on Monday through Friday, else returns false.**
123
+
124
+ ```ruby
125
+ Date.new(2012,1,1).working_day?
126
+ # => false
127
+
128
+ Date.new(2012,2,3).working_day?
129
+ # => true
130
+ ```
131
+
132
+ **Returns true if date falls on Saturday or Sunday, else returns false.**
133
+
134
+ ```ruby
135
+ Date.new(2012,1,1).week_end?
136
+ # => true
137
+
138
+ Date.new(2012,2,3).week_end?
139
+ # => false
140
+ ```
141
+
142
+
143
+
144
+
145
+
146
+ ## Tools Being Used
147
+
148
+ We believe strongly in not writing code unless we have to, so Week of month is built using:
149
+
150
+ * Ruby Date Class
151
+
152
+ * Ruby Time Class
153
+
154
+ ## Version History
155
+
156
+ ###1.2.1
157
+
158
+ Support for Time class
159
+
160
+ **Methods Added:**
161
+
162
+ name_of_week_day, name_of_month, week_end?, working_day?,
163
+ all_sundays_in_month, all_mondays_in_month, all_tuesdays_in_month,
164
+ all_wednesdays_in_month, all_thursdays_in_month, all_fridays_in_month,
165
+ all_saturdays_in_month
166
+
167
+ ###1.1.0
168
+
169
+ ActiveSupport Dependency removed
170
+
171
+ **Methods Added:**
172
+
173
+ january?, february?, march?, april?, may?, june?, july?,
174
+ august?, september?, october?, november?, december?, last_day_of_month
175
+
176
+ ## Contributing to Week of month
177
+
178
+ Fork, fix, then send me a pull request.
179
+
180
+ ## License
181
+
182
+ MIT
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
2
3
 
3
4
  Rake::TestTask.new do |t|
4
5
  t.libs << "test"
@@ -6,35 +6,35 @@
6
6
  module WeekOfMonth
7
7
  module Constant
8
8
 
9
- # hash containg english words from one to seventh
9
+ # hash containing english words from one to seven
10
10
  WEEK_OF_MONTH_IN_ENG = { 1 => 'First', 2 => 'Second', 3 => 'Third',
11
11
  4 => 'Fourth', 5 => 'Fifth', 6 => 'Sixth', 7 => 'Seventh'}
12
12
 
13
- # hash containg french words from one to seventh
13
+ # hash containing french words from one to seven
14
14
  WEEK_OF_MONTH_IN_FR = { 1 => 'First', 2 => 'Second', 3 => 'Third',
15
15
  4 => 'Quatrième', 5 => 'Cinquième', 6 => 'sixième', 7 => 'septième'}
16
16
 
17
- # hash containg german words from one to seventh
17
+ # hash containing german words from one to seven
18
18
  WEEK_OF_MONTH_IN_GER = { 1 => 'First', 2 => 'Second', 3 => 'Dritten',
19
19
  4 => 'Vierte', 5 => 'Fünfte', 6 => 'Sechste', 7 => 'siebte'}
20
20
 
21
- # hash containg japneese words from one to seventh
21
+ # hash containing japneese words from one to seven
22
22
  WEEK_OF_MONTH_IN_JAP = { 1 => '最初', 2 => '秒', 3 => 'サード',
23
23
  4 => '第4回', 5 => '第五', 6=> 'シックス', 7 => '第7' }
24
24
 
25
- # hash containg month name with days in that month(in non leap yaer)
25
+ # hash containing month name with days in that month(in non leap yaer)
26
26
  MONTH_WITH_DAY = { :january => 31, :february => 28, :march => 31,
27
27
  :april => 30, :may => 31, :june => 30, :july => 31,
28
28
  :august => 31, :september => 30, :october => 31,
29
29
  :november => 30, :december => 31 }
30
30
 
31
- # hash containg month names with their sequence
31
+ # hash containing month names with their sequence
32
32
  MONTH_WITH_SEQUENCE = { :january => 1, :february => 2, :march => 3,
33
33
  :april => 4, :may => 5, :june => 6, :july => 7,
34
34
  :august => 8, :september => 9, :october => 10,
35
35
  :november => 11, :december => 12 }
36
36
 
37
- # array of days names ordered starting with sunday and ending with saturday.
37
+ # array of days names ordered starting with sunday and ending with saturday.
38
38
  DAYS_IN_SEQUENCE = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
39
39
  "Saturday"]
40
40
  end
data/lib/modules/day.rb CHANGED
@@ -29,7 +29,7 @@ module WeekOfMonth
29
29
  self.class.new(year,month,day).strftime('%A')
30
30
  end
31
31
 
32
- # this code generates method names like 'upcomong_monday' and 'previous_monday'
32
+ # this code generates method names like 'upcoming_monday' and 'previous_monday'
33
33
  # Date.new(2013,1,1).upcoming_monday
34
34
  # => #<Date: 2013-01-07 ((2456300j,0s,0n),+0s,2299161j)>
35
35
  # Date.new(2013,1,1).previous_monday
@@ -0,0 +1,5 @@
1
+ # @author Sachin Singh
2
+
3
+ module WeekOfMonth
4
+ VERSION = '1.2.3.2'
5
+ end
data/lib/week_of_month.rb CHANGED
@@ -1,32 +1,44 @@
1
1
  require 'date'
2
2
  require 'time'
3
3
 
4
- RUBY_VERSION < '1.9' ? require('modules/day') : require_relative('modules/day')
5
- RUBY_VERSION < '1.9' ? require('modules/month') : require_relative('modules/month')
6
- RUBY_VERSION < '1.9' ? require('modules/week') : require_relative('modules/week')
7
- RUBY_VERSION < '1.9' ? require('modules/year') : require_relative('modules/year')
4
+ def require_file file_name
5
+ RUBY_VERSION < '1.9' ? require(file_name) : require_relative(file_name)
6
+ end
7
+
8
+ require_file 'modules/day'
9
+ require_file 'modules/month'
10
+ require_file 'modules/week'
11
+ require_file 'modules/year'
8
12
 
9
13
  class Date
10
14
  include WeekOfMonth::Day
11
15
  include WeekOfMonth::Month
12
16
  include WeekOfMonth::Week
13
17
  include WeekOfMonth::Year
18
+ end
14
19
 
15
- unless method_defined?(:to_date)
16
- def to_date
17
- ::Date.new(year, month, day)
20
+ [Time, Date].each do |klass|
21
+
22
+ klass.class_eval do
23
+
24
+ unless method_defined?(:to_date)
25
+ def to_date
26
+ ::Date.new(year, month, day)
27
+ end
28
+ end
29
+
30
+ unless method_defined?(:sunday?)
31
+ def sunday? ; self.wday == 0; end
32
+ def monday? ; self.wday == 1; end
33
+ def tuesday? ; self.wday == 2; end
34
+ def wednesday? ; self.wday == 3; end
35
+ def thursday? ; self.wday == 4; end
36
+ def friday? ; self.wday == 5; end
37
+ def saturday? ; self.wday == 6; end
18
38
  end
19
- end
20
39
 
21
- unless method_defined?(:sunday?)
22
- def sunday? ; self.wday == 0; end
23
- def monday? ; self.wday == 1; end
24
- def tuesday? ; self.wday == 2; end
25
- def wednesday? ; self.wday == 3; end
26
- def thursday? ; self.wday == 4; end
27
- def friday? ; self.wday == 5; end
28
- def saturday? ; self.wday == 6; end
29
40
  end
41
+
30
42
  end
31
43
 
32
44
  class Time
@@ -44,21 +56,6 @@ class Time
44
56
  Time.local(year, month, day, hour, min, sec, millisecond)
45
57
  end
46
58
  end
47
-
48
- unless method_defined?(:to_date)
49
- def to_date
50
- ::Date.new(year, month, day)
51
- end
52
- end
53
- unless method_defined?(:sunday?)
54
- def sunday? ; self.wday == 0; end
55
- def monday? ; self.wday == 1; end
56
- def tuesday? ; self.wday == 2; end
57
- def wednesday? ; self.wday == 3; end
58
- def thursday? ; self.wday == 4; end
59
- def friday? ; self.wday == 5; end
60
- def saturday? ; self.wday == 6; end
61
- end
62
59
  end
63
60
 
64
61
  class Hash
@@ -71,3 +68,19 @@ class Hash
71
68
  end
72
69
  end
73
70
 
71
+ module WeekOfMonth
72
+
73
+ def self.first_day=val
74
+ @first_day = DAYS_IN_SEQUENCE[val]
75
+ end
76
+
77
+ def self.first_day
78
+ @first_day ||= 0
79
+ end
80
+
81
+ def self.configure
82
+ yield
83
+ end
84
+
85
+ end
86
+
@@ -1,13 +1,18 @@
1
+ require File.expand_path('../lib/modules/version', __FILE__)
2
+
1
3
  Gem::Specification.new do |s|
2
- s.name = 'week_of_month'
3
- s.version = '1.2.3.1'
4
- s.date = '2014-04-27'
5
- s.summary = "Week Of Month!"
6
- s.description = "Its gives you week_of_month method on date and time objects, that returns week of the month."
7
- s.authors = ["Sachin Singh"]
8
- s.email = 'sachin@railsdeveloper.in'
9
- s.homepage = 'https://github.com/sachin87/week-of-month'
4
+ s.name = 'week_of_month'
5
+ s.version = WeekOfMonth::VERSION
6
+ s.date = '2014-07-28'
7
+ s.summary = 'Week Of Month!'
8
+ s.description = 'Its gives you week_of_month method on date and time objects, that returns week of the month.'
9
+ s.authors = ['Sachin Singh', 'Tommy']
10
+ s.email = ['sachin@railsdeveloper.in', 'sachin.y87@gmail.com', 'singhsachin87@yahoo.com']
11
+ s.homepage = 'https://github.com/sachin87/week-of-month'
10
12
  s.files = `git ls-files`.split("\n").sort
11
- s.require_paths = ["lib"]
12
- s.license = 'MIT'
13
+ s.require_paths = ['lib']
14
+ s.license = 'MIT'
15
+
16
+ s.add_development_dependency 'rake', '>= 10.1.0'
17
+ s.add_development_dependency 'bundler', '>= 1.0'
13
18
  end
metadata CHANGED
@@ -1,30 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: week_of_month
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3.1
4
+ version: 1.2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sachin Singh
8
+ - Tommy
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
12
- dependencies: []
12
+ date: 2014-07-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 10.1.0
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 10.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '1.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '1.0'
13
42
  description: Its gives you week_of_month method on date and time objects, that returns
14
43
  week of the month.
15
- email: sachin@railsdeveloper.in
44
+ email:
45
+ - sachin@railsdeveloper.in
46
+ - sachin.y87@gmail.com
47
+ - singhsachin87@yahoo.com
16
48
  executables: []
17
49
  extensions: []
18
50
  extra_rdoc_files: []
19
51
  files:
20
- - .gitignore
52
+ - ".bundle/install.log"
53
+ - ".gitignore"
21
54
  - Gemfile
22
55
  - Gemfile.lock
23
- - README.rdoc
56
+ - README.md
24
57
  - Rakefile
25
58
  - lib/modules/constant.rb
26
59
  - lib/modules/day.rb
27
60
  - lib/modules/month.rb
61
+ - lib/modules/version.rb
28
62
  - lib/modules/week.rb
29
63
  - lib/modules/year.rb
30
64
  - lib/test/modules/test_constant.rb
@@ -45,17 +79,17 @@ require_paths:
45
79
  - lib
46
80
  required_ruby_version: !ruby/object:Gem::Requirement
47
81
  requirements:
48
- - - '>='
82
+ - - ">="
49
83
  - !ruby/object:Gem::Version
50
84
  version: '0'
51
85
  required_rubygems_version: !ruby/object:Gem::Requirement
52
86
  requirements:
53
- - - '>='
87
+ - - ">="
54
88
  - !ruby/object:Gem::Version
55
89
  version: '0'
56
90
  requirements: []
57
91
  rubyforge_project:
58
- rubygems_version: 2.0.3
92
+ rubygems_version: 2.2.2
59
93
  signing_key:
60
94
  specification_version: 4
61
95
  summary: Week Of Month!
data/README.rdoc DELETED
@@ -1,88 +0,0 @@
1
- = Week Of Month
2
-
3
- Week Of Month is a library which gives you week_of_month method on Date and Time
4
- class object, that returns week of the month. It basically extends the Date and Time
5
- class with several useful date helpers.
6
-
7
- == Getting Started
8
-
9
- Week Of Month is released as a Ruby Gem. The gem is to be installed within a Ruby
10
- or Rails application. To install, simply add the following to your Gemfile:
11
-
12
- gem 'week_of_month'
13
-
14
- Run bundle install and don't forget to restart your server after you install a new gem.
15
-
16
- == Usage
17
-
18
- It returns week split of that date's month
19
-
20
- Date.new(2012,1,1).week_split
21
-
22
- => [[1, 2, 3, 4, 5, 6, 7],
23
- [8, 9, 10, 11, 12, 13, 14],
24
- [15, 16, 17, 18, 19, 20, 21],
25
- [22, 23, 24, 25, 26, 27, 28],
26
- [29, 30, 31]]
27
-
28
- It returns month's week in which the date lies
29
-
30
- Date.new(2012,1,1).week_of_month => 1
31
-
32
- It return true if date lies in first week of month, else false.
33
-
34
- Date.new(2012,1,1).first_week? => true
35
-
36
- It returns true if date lies in second week of month, else false.
37
-
38
- Date.new(2012,1,9).second_week? => true
39
-
40
- It returns true if date lies in last week of month, else false.
41
-
42
- Date.new(2012,1,31).last_week? => true
43
-
44
- It returns total number of weeks in month.
45
-
46
- Date.new(2012,1,31).total_weeks => 5
47
-
48
- It returns month's week in which the date lies
49
-
50
- Date.new(2012,1,31).week_of_month_in_eng => "Fifth"
51
-
52
- == Tools Being Used
53
-
54
- We believe strongly in not writing code unless we have to, so Week Of Month is built using
55
-
56
- Ruby Date Class
57
-
58
- Ruby Time Class
59
-
60
- == Version History
61
-
62
- 1.2.1
63
-
64
- Support for Time class
65
-
66
- Methods Added
67
-
68
- name_of_week_day, name_of_month, week_end?, working_day?,
69
- all_sundays_in_month, all_mondays_in_month, all_tuesdays_in_month,
70
- all_wednesdays_in_month, all_thursdays_in_month, all_fridays_in_month,
71
- all_saturdays_in_month
72
-
73
- 1.1.0
74
-
75
- ActiveSupport Dependency removed
76
-
77
- Methods Added
78
-
79
- january?, february?, march?, april?, may?, june?, july?,
80
- august?, september?, october?, november?, december?, last_day_of_month
81
-
82
- == Contributing to Week Of Month
83
-
84
- Fork, fix, then send me a pull request.
85
-
86
- ## License
87
-
88
- use MIT license.