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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cddd4a79f948d7a8b39e5fe26e9e06b22c985730
4
- data.tar.gz: 62686392677a4ab4063e86e23ac0f52045ed127a
3
+ metadata.gz: 9b16768a27ed6cdd9dcb9e63511f2e8fa8d3c76a
4
+ data.tar.gz: 269f56a5011606d2f3430b5260d5933ce49df454
5
5
  SHA512:
6
- metadata.gz: a72d84b8e47b0b883e7f361e02e462a3304cabdfb82d8053c9b81277b8464b744abed04e22beec215df1d45c5467ea3c22e57e04ca6aa2123408056b146736ec
7
- data.tar.gz: 07d526280f512b32388a84f3b368f4bf5d6f0160e6364ff872f16456dbde30e39164f253d0c20ccd66565deefdf4aa1df76ee45502a77088b271a913d43e72f5
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-2016 Craig Little. See [LICENSE][license] for details.
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, number_of_days)
6
- @schedule = schedule
7
- @number_of_days = Integer(number_of_days)
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(date)
11
- schedule.before(date).take(number_of_days).to_a.last
12
+ def before(origin)
13
+ calculated_day(:before, origin)
12
14
  end
13
15
 
14
- def after(date)
15
- schedule.after(date).take(number_of_days).to_a.last
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
- :number_of_days
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(&Time::WEEKDAYS.method(:include?))
13
- .map(&Time::WEEKDAYS.method(:index))
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 ||= begin
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 ||= begin
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
@@ -1,3 +1,3 @@
1
1
  module Clavius
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
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.2
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: 2016-02-12 00:00:00.000000000 Z
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.0'
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.4.5.1
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: