Weekend 0.1.0 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f18d168acca7f5b6af5d68d0bdd622ee8101ccbe
4
- data.tar.gz: 53b58871762aa9910cf228e25b9db08f8818835e
3
+ metadata.gz: 764b187f3258268b232b250e9db4ade1269db689
4
+ data.tar.gz: fab87db4c0f28764f3134282591a829e2385d6ac
5
5
  SHA512:
6
- metadata.gz: d4dd890d935ac94f1f21b629b0d4b03f65398f26a8b4fdbc18324d478f5920901083a0797a34fd887eda20ab9245bb518586ae28282db68caa860573b3605fee
7
- data.tar.gz: f9bcaebfae57c6fc91ba4e9997ec261aa84cb1c3792a63d44d0f1c68a0b55ed18721d8dd23f1181b8e4ed0fa81facde47b80bbb921d3a02604760ba33233e420
6
+ metadata.gz: 0ecd3139e16a98ddb43bace743c3a807b81a53e39856d6ee9f9166984616c8bacf029782958192b03859d191068de43064e1d24d3158640878a7a50c7aa70778
7
+ data.tar.gz: 6c932c42a9aaf27bcdf725a1a0490230b629aead715ee3009f40d3e62f43e95f9b229c00647e803c7d4b4f8d9618df25b6453686a878546c7a139259178bde53
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ lib/.DS_Store
data/README.md CHANGED
@@ -22,13 +22,53 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Weekend::Base is base class.
26
26
 
27
- ## Development
27
+ 1) For filtering weekends(only weekdays) :
28
28
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
29
+ ```Weekend::Base.filter_weekends(start_date, end_date)```
30
+
31
+ e.g. ```Weekend::Base.filter_weekends(Date.today, Date.today + 6) => [#<Date: 2015-07-07 ((2457211j,0s,0n),+0s,2299161j)>, #<Date: 2015-07-08 ((2457212j,0s,0n),+0s,2299161j)>, #<Date: 2015-07-09 ((2457213j,0s,0n),+0s,2299161j)>, #<Date: 2015-07-10 ((2457214j,0s,0n),+0s,2299161j)>, #<Date: 2015-07-13 ((2457217j,0s,0n),+0s,2299161j)>]```
32
+
33
+ 2) For filtering weekdays(only weekends) :
34
+
35
+ ```Weekend::Base.filter_weekdays(start_date, end_date)```
36
+
37
+ e.g. ```Weekend::Base.filter_weekdays(Date.today, Date.today + 6) => [#<Date: 2015-07-11 ((2457215j,0s,0n),+0s,2299161j)>, #<Date: 2015-07-12 ((2457216j,0s,0n),+0s,2299161j)>]```
38
+
39
+ 3) For total no of working days :
40
+
41
+ ```Weekend::Base.no_of_working_days(start_date, end_date)```
42
+
43
+ e.g. ```Weekend::Base.no_of_working_days(Date.today, Date.today + 6) => 5```
44
+
45
+ 4) For total no of weekends :
46
+
47
+ ```Weekend::Base.no_of_weekends(start_date, end_date)```
48
+
49
+ e.g. ```Weekend::Base.no_of_weekends(Date.today, Date.today + 6) => 2```
50
+
51
+ 5) Similarly for getting no. of sundays, mondays & so on....we have :
52
+
53
+ ```Weekend::Base.no_of_sundays(start_date, end_date)```
54
+
55
+ ```Weekend::Base.no_of_mondays(start_date, end_date)```
56
+
57
+ ```Weekend::Base.no_of_tuesdays(start_date, end_date)```
58
+
59
+ ```Weekend::Base.no_of_wednesdays(start_date, end_date)```
60
+
61
+ ```Weekend::Base.no_of_thursdays(start_date, end_date)```
62
+
63
+ ```Weekend::Base.no_of_fridays(start_date, end_date)```
64
+
65
+ ```Weekend::Base.no_of_saturdays(start_date, end_date)```
66
+
67
+
68
+ ## Future Enhancements
69
+
70
+ 1. Add concept of holidays, so that one can get actual no. of working days
30
71
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
72
 
33
73
  ## Contributing
34
74
 
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
11
11
 
12
12
  spec.summary = %q{Gem for basic but helpful week days related queries.}
13
13
  spec.description = %q{}
14
- spec.homepage = "http://www.tusharmaroo.com"
14
+ spec.homepage = "https://github.com/tusharmaroo/weekend"
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -1,81 +1,7 @@
1
1
  require "Weekend/version"
2
+ require "Weekend/base"
2
3
  require 'date'
3
4
 
4
5
  module Weekend
5
- # Your code goes here...
6
- # filter weekends
7
- def self.filter_weekends start_date, end_date
8
- result(start_date,end_date,[1,2,3,4,5])
9
- end
10
-
11
- #filter weekdays
12
- def self.filter_weekdays start_date, end_date
13
- result(start_date,end_date,[0,6])
14
- end
15
-
16
- # total working days(except weekends)
17
- def self.no_of_working_days start_date, end_date
18
- filter_weekends(start_date,end_date).count
19
- end
20
-
21
- # no of weekends
22
- def self.no_of_weekends start_date, end_date
23
- filter_weekdays(start_date,end_date).count
24
- end
25
-
26
- def self.result start_date, end_date, arr_of_days
27
- ((start_date.to_date)..(end_date.to_date)).to_a.select {|k| arr_of_days.include?(k.wday)}
28
- end
29
- # no of sundays/mondays/tuesdays etc
30
-
31
- # all_days = ["Sunday", "Monday", "Tuesday","Wednesday","Thrusday","Friday","Saturday"]
32
-
33
- # def self.all_days
34
- # ["Sunday", "Monday", "Tuesday","Wednesday","Thrusday","Friday","Saturday"]
35
- # end
36
- # def self.included(base)
37
- # base.extend ClassMethods
38
- # end
39
-
40
- # module ClassMethods
41
- # all_days = ["Sunday", "Monday", "Tuesday","Wednesday","Thrusday","Friday","Saturday"]
42
-
43
- # def no_of_days(day)
44
- # Weekend.tushar
45
- # end
46
-
47
- def self.no_of_sundays start_date, end_date
48
- result(start_date,end_date,[0]).count
49
- end
50
-
51
- def self.no_of_mondays start_date, end_date
52
- result(start_date,end_date,[1]).count
53
- end
54
-
55
- def self.no_of_tuesdays start_date, end_date
56
- result(start_date,end_date,[2]).count
57
- end
58
-
59
- def self.no_of_wednesdays start_date, end_date
60
- result(start_date,end_date,[3]).count
61
- end
62
-
63
- def self.no_of_thrusdays start_date, end_date
64
- result(start_date,end_date,[4]).count
65
- end
66
-
67
- def self.no_of_fridays start_date, end_date
68
- result(start_date,end_date,[5]).count
69
- end
70
-
71
- def self.no_of_saturdays start_date, end_date
72
- result(start_date,end_date,[6]).count
73
- end
74
-
75
- # ["Sunday", "Monday", "Tuesday","Wednesday","Thrusday","Friday","Saturday"].each do |day|
76
- # method_name = day.to_sym
77
- # define_method(method_name) { no_of_days }
78
- # end
79
- # end
80
-
81
- end
6
+ #All logic placed inside base class
7
+ end
@@ -0,0 +1,34 @@
1
+ class Weekend::Base
2
+ class << self
3
+ #Filtering weekends
4
+ def filter_weekends start_date, end_date
5
+ result(start_date,end_date,[1,2,3,4,5])
6
+ end
7
+
8
+ #filter weekdays
9
+ def filter_weekdays start_date, end_date
10
+ result(start_date,end_date,[0,6])
11
+ end
12
+
13
+ # total working days(except weekends)
14
+ def no_of_working_days start_date, end_date
15
+ filter_weekends(start_date,end_date).count
16
+ end
17
+
18
+ # no of weekends
19
+ def no_of_weekends start_date, end_date
20
+ filter_weekdays(start_date,end_date).count
21
+ end
22
+
23
+ def result start_date, end_date, arr_of_days
24
+ ((start_date.to_date)..(end_date.to_date)).to_a.select {|k| arr_of_days.include?(k.wday)}
25
+ end
26
+
27
+ #Generates methods like no_of_sundays, no_of_mondays etc
28
+ ["Sunday", "Monday", "Tuesday","Wednesday","Thursday","Friday","Saturday"].each_with_index do |day,index|
29
+ define_method("no_of_#{day.downcase}s") { |start_date,end_date| result(start_date,end_date,[index]).count }
30
+ end
31
+ end
32
+ end
33
+
34
+
@@ -1,3 +1,3 @@
1
1
  module Weekend
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Weekend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tushar Maroo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-17 00:00:00.000000000 Z
11
+ date: 2015-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,8 +71,9 @@ files:
71
71
  - bin/console
72
72
  - bin/setup
73
73
  - lib/Weekend.rb
74
+ - lib/Weekend/base.rb
74
75
  - lib/Weekend/version.rb
75
- homepage: http://www.tusharmaroo.com
76
+ homepage: https://github.com/tusharmaroo/weekend
76
77
  licenses:
77
78
  - MIT
78
79
  metadata: {}
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  version: '0'
93
94
  requirements: []
94
95
  rubyforge_project:
95
- rubygems_version: 2.2.2
96
+ rubygems_version: 2.4.6
96
97
  signing_key:
97
98
  specification_version: 4
98
99
  summary: Gem for basic but helpful week days related queries.