clavius 1.0.2 → 1.0.3
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/clavius/calculation/days_from.rb +32 -8
- data/lib/clavius/configuration.rb +14 -18
- data/lib/clavius/version.rb +1 -1
- metadata +5 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b16768a27ed6cdd9dcb9e63511f2e8fa8d3c76a
|
4
|
+
data.tar.gz: 269f56a5011606d2f3430b5260d5933ce49df454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf5622090868d74651191a6ade3d1f1ef2c3ebb3ba5c133db75d0ac6243b021e796651412b3936aeda200a0772e0a2b2438452ba6f3e31f46bffd42013142bf2
|
7
|
+
data.tar.gz: 000e1fa061968681cf7ed7282b0c988baec5fafdd152b909afaf12340cf746e50f43dc98b95474bd23bac6941140c7e51cfde20b676dbe654a36aeae7db28116
|
data/README.md
CHANGED
@@ -46,6 +46,6 @@ for commit messages.
|
|
46
46
|
|
47
47
|
## Copyright
|
48
48
|
|
49
|
-
Copyright (c) 2015-
|
49
|
+
Copyright (c) 2015-2017 Craig Little. See [LICENSE][license] for details.
|
50
50
|
|
51
51
|
[license]: https://github.com/craiglittle/clavius/blob/master/LICENSE
|
@@ -2,23 +2,47 @@ module Clavius
|
|
2
2
|
module Calculation
|
3
3
|
class DaysFrom
|
4
4
|
|
5
|
-
def initialize(schedule,
|
6
|
-
@schedule
|
7
|
-
@
|
5
|
+
def initialize(schedule, number)
|
6
|
+
@schedule = schedule
|
7
|
+
@number = Integer(number)
|
8
|
+
|
9
|
+
fail ArgumentError, 'negative number' if @number < 0
|
8
10
|
end
|
9
11
|
|
10
|
-
def before(
|
11
|
-
|
12
|
+
def before(origin)
|
13
|
+
calculated_day(:before, origin)
|
12
14
|
end
|
13
15
|
|
14
|
-
def after(
|
15
|
-
|
16
|
+
def after(origin)
|
17
|
+
calculated_day(:after, origin)
|
16
18
|
end
|
17
19
|
|
18
20
|
protected
|
19
21
|
|
20
22
|
attr_reader :schedule,
|
21
|
-
:
|
23
|
+
:number
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def calculated_day(direction, origin)
|
28
|
+
return zeroeth_day(direction, origin) if number.zero?
|
29
|
+
|
30
|
+
schedule.public_send(direction, origin).take(number).to_a.last
|
31
|
+
end
|
32
|
+
|
33
|
+
def zeroeth_day(direction, origin)
|
34
|
+
self
|
35
|
+
.class
|
36
|
+
.new(schedule, 1)
|
37
|
+
.public_send(direction, zeroeth_origin(direction, origin))
|
38
|
+
end
|
39
|
+
|
40
|
+
def zeroeth_origin(direction, origin)
|
41
|
+
case direction
|
42
|
+
when :before then origin.next_day
|
43
|
+
when :after then origin.prev_day
|
44
|
+
end
|
45
|
+
end
|
22
46
|
|
23
47
|
end
|
24
48
|
end
|
@@ -9,39 +9,35 @@ module Clavius
|
|
9
9
|
@weekdays ||= begin
|
10
10
|
raw
|
11
11
|
.weekdays
|
12
|
-
.select
|
13
|
-
.map
|
12
|
+
.select { |weekday| Time::WEEKDAYS.include?(weekday) }
|
13
|
+
.map { |weekday| Time::WEEKDAYS.index(weekday) }
|
14
14
|
.to_set
|
15
15
|
.freeze
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def included
|
20
|
-
@included ||=
|
21
|
-
raw
|
22
|
-
.included
|
23
|
-
.select { |date| date.respond_to?(:to_date) }
|
24
|
-
.map(&:to_date)
|
25
|
-
.to_set
|
26
|
-
.freeze
|
27
|
-
end
|
20
|
+
@included ||= exception_configuration(raw.included)
|
28
21
|
end
|
29
22
|
|
30
23
|
def excluded
|
31
|
-
@excluded ||=
|
32
|
-
raw
|
33
|
-
.excluded
|
34
|
-
.select { |date| date.respond_to?(:to_date) }
|
35
|
-
.map(&:to_date)
|
36
|
-
.to_set
|
37
|
-
.freeze
|
38
|
-
end
|
24
|
+
@excluded ||= exception_configuration(raw.excluded)
|
39
25
|
end
|
40
26
|
|
41
27
|
protected
|
42
28
|
|
43
29
|
attr_reader :raw
|
44
30
|
|
31
|
+
private
|
32
|
+
|
33
|
+
def exception_configuration(dates)
|
34
|
+
dates
|
35
|
+
.select { |date| date.respond_to?(:to_date) }
|
36
|
+
.map(&:to_date)
|
37
|
+
.to_set
|
38
|
+
.freeze
|
39
|
+
end
|
40
|
+
|
45
41
|
Raw = Struct.new(:weekdays, :included, :excluded) do
|
46
42
|
module Default
|
47
43
|
WEEKDAYS = Set.new(%i[mon tue wed thu fri]).freeze
|
data/lib/clavius/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clavius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Little
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rake
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '10.0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '10.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.0'
|
11
|
+
date: 2017-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
41
13
|
description: Date calculations based on a schedule.
|
42
14
|
email:
|
43
15
|
- craiglttl@gmail.com
|
@@ -65,7 +37,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
37
|
requirements:
|
66
38
|
- - ">="
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version: '2.
|
40
|
+
version: '2.2'
|
69
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
42
|
requirements:
|
71
43
|
- - ">="
|
@@ -73,9 +45,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
45
|
version: '0'
|
74
46
|
requirements: []
|
75
47
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
48
|
+
rubygems_version: 2.6.8
|
77
49
|
signing_key:
|
78
50
|
specification_version: 4
|
79
51
|
summary: Date calculations
|
80
52
|
test_files: []
|
81
|
-
has_rdoc:
|