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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c70cf6d890ee4e9e53a17816dd772e6ff273957
4
- data.tar.gz: 5aae575a665953edd5edbe8bc588e1a689ee490b
3
+ metadata.gz: ea7a7f37a90fa0c1b94c2bc9cf0e2f73f7e4db19
4
+ data.tar.gz: f25ff9d65eeb94b8da2849bf55f59c634366ba25
5
5
  SHA512:
6
- metadata.gz: 8503d9d2a81a89c915665596f22af624c0c92454deadcac016c3ac21b1f86114d934725cfde2a7f20b98d27aa526f8df8e811f452b450fc476cdb36b43f9fa9c
7
- data.tar.gz: 234b43a5926e486eef5967172b25ab4c10c84869957919b1a2e9f05a59152df0417d41da3efaa551da91e3499c4f57b899a1d07c31c045c859a7709c9e96cf7e
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
 
@@ -0,0 +1,11 @@
1
+ class NotKindOfTimeError < StandardError
2
+ def initialize(message = nil)
3
+ super(message || default_message)
4
+ end
5
+
6
+ private
7
+
8
+ def default_message
9
+ 'Argument not respond to #to_time (not kind of Time, Date or DateTime)'
10
+ end
11
+ end
@@ -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
@@ -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)
@@ -1,7 +1,12 @@
1
1
  module Weekends
2
2
  module OnDate
3
3
  def on_date?(date)
4
+ date = time_coerced(date)
4
5
  date.wday.zero? || date.wday == 6
5
6
  end
7
+
8
+ def today?
9
+ on_date?(Time.now)
10
+ end
6
11
  end
7
12
  end
@@ -1,3 +1,3 @@
1
1
  module Weekends
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -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 #near and #today?'
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.0
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-02 00:00:00.000000000 Z
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 #near and #today?'
101
+ summary: 'Weekend class with methods like #nearest_weekend, #on_date? and #today?'
101
102
  test_files: []