weekends 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/errors/not_kind_of_time.rb +11 -0
- data/lib/weekend.rb +9 -0
- data/lib/weekends/nearest.rb +6 -0
- data/lib/weekends/on_date.rb +5 -0
- data/lib/weekends/version.rb +1 -1
- data/weekends.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea7a7f37a90fa0c1b94c2bc9cf0e2f73f7e4db19
|
4
|
+
data.tar.gz: f25ff9d65eeb94b8da2849bf55f59c634366ba25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4d23a7c557c7f5c939a1483565da3dc95afa25211bc8463e7842e524d39943078d92aa82d12709631f6a7e0d7002ce8f0265c38fe459531db751be7319c8552
|
7
|
+
data.tar.gz: 9345795273c896d00121c89e7998eaf0b4e2ee90bf8bb862a25c69adf76f9806db74de1a4407fdc10d65ac40475e2b7598aac0f18c052cf2d793979031d3dfed
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Weekends [![Build Status](https://travis-ci.org/GeorgeGorbanev/weekends.svg?branch=master)](https://travis-ci.org/GeorgeGorbanev/weekends)
|
1
|
+
# Weekends [![Build Status](https://travis-ci.org/GeorgeGorbanev/weekends.svg?branch=master)](https://travis-ci.org/GeorgeGorbanev/weekends) [![Gem Version](https://badge.fury.io/rb/weekends.svg)](https://badge.fury.io/rb/weekends)
|
2
2
|
|
3
3
|
This gem import class `Weekend` that help to identify weekend dates.
|
4
4
|
|
data/lib/weekend.rb
CHANGED
@@ -6,5 +6,14 @@ class Weekend
|
|
6
6
|
class << self
|
7
7
|
include Weekends::Nearest
|
8
8
|
include Weekends::OnDate
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def time_coerced(date)
|
13
|
+
return date if date.instance_of?(Time)
|
14
|
+
raise NotKindOfTimeError unless date.respond_to?(:to_time)
|
15
|
+
|
16
|
+
date.to_time
|
17
|
+
end
|
9
18
|
end
|
10
19
|
end
|
data/lib/weekends/nearest.rb
CHANGED
@@ -3,18 +3,24 @@ module Weekends
|
|
3
3
|
DAY = 86_400
|
4
4
|
|
5
5
|
def nearest_saturday(date)
|
6
|
+
date = time_coerced(date)
|
7
|
+
|
6
8
|
wday = date.wday
|
7
9
|
diff = wday == 6 ? 7 : 6 - wday
|
8
10
|
date + diff * DAY
|
9
11
|
end
|
10
12
|
|
11
13
|
def nearest_sunday(date)
|
14
|
+
date = time_coerced(date)
|
15
|
+
|
12
16
|
wday = date.wday
|
13
17
|
diff = wday == 7 ? 7 : 7 - wday
|
14
18
|
date + diff * DAY
|
15
19
|
end
|
16
20
|
|
17
21
|
def nearest_full_weekends(date)
|
22
|
+
date = time_coerced(date)
|
23
|
+
|
18
24
|
if on_date?(date)
|
19
25
|
current_weekend_end = nearest_sunday(date)
|
20
26
|
next_saturday = nearest_saturday(current_weekend_end)
|
data/lib/weekends/on_date.rb
CHANGED
data/lib/weekends/version.rb
CHANGED
data/weekends.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['GeorgeGorbanev']
|
9
9
|
spec.email = ['GeorgeGorbanev@gmail.com']
|
10
10
|
|
11
|
-
spec.summary = 'Weekend class with methods like #
|
11
|
+
spec.summary = 'Weekend class with methods like #nearest_weekend, #on_date? and #today?'
|
12
12
|
spec.homepage = 'https://github.com/GeorgeGorbanev/weekends'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weekends
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GeorgeGorbanev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- bin/console
|
71
71
|
- bin/setup
|
72
|
+
- lib/errors/not_kind_of_time.rb
|
72
73
|
- lib/weekend.rb
|
73
74
|
- lib/weekends/nearest.rb
|
74
75
|
- lib/weekends/on_date.rb
|
@@ -97,5 +98,5 @@ rubyforge_project:
|
|
97
98
|
rubygems_version: 2.6.10
|
98
99
|
signing_key:
|
99
100
|
specification_version: 4
|
100
|
-
summary: 'Weekend class with methods like #
|
101
|
+
summary: 'Weekend class with methods like #nearest_weekend, #on_date? and #today?'
|
101
102
|
test_files: []
|