upcoming 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: ccef27184948b16da3feecded92350ac1fe53983
4
- data.tar.gz: 00efad8af30f96ffe666be793e581af3d02c40f0
3
+ metadata.gz: f262a85c40d0c408b913135974601da00d4d89d1
4
+ data.tar.gz: 6dbac7937346f821d7c0aa7611d7f1d5954b7a00
5
5
  SHA512:
6
- metadata.gz: 27976606835d81a76dfcc4204fe186d880e693db5e056d4e8b86e536ab70dea2d284110544e2d67b03149f54a7c498f1de18fa4da9c7ec0b55185aa7bf3aedc0
7
- data.tar.gz: 67c27a1f8a237a102aef6f45250726285633a51d84c0da81f957e855c230f062cd42415883a9706233754a5a5980fa6689c08a6a8e5368180fc85316c7aec9d6
6
+ metadata.gz: 1be5ca77077ce49852a700796164db3cd94611e535fa81139fa69db513257baeab5db0dd80b61273a34e59658a3d00b5f3d74065e7120996b51a027a68e4c932
7
+ data.tar.gz: 746ef6accdd1c981004b49819d61cd0796297abbc925d9e92a6716efc4cae621c6b353abeb11a3dcce50325adefe60199a73f429b2f262215c0f00e6a736ecb5
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (C) 2014 David Lantos
1
+ Copyright (C) 2014-2016 David Lantos
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # upcoming
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/upcoming.png)](http://badge.fury.io/rb/upcoming)
3
+ [![Gem Version](https://badge.fury.io/rb/upcoming.svg)](http://badge.fury.io/rb/upcoming)
4
4
  [![Build Status](https://travis-ci.org/sldblog/upcoming.svg)](https://travis-ci.org/sldblog/upcoming)
5
5
  [![Code Climate](https://codeclimate.com/github/sldblog/upcoming.png)](https://codeclimate.com/github/sldblog/upcoming)
6
6
  [![Dependency Status](https://gemnasium.com/sldblog/upcoming.svg)](https://gemnasium.com/sldblog/upcoming)
@@ -14,27 +14,48 @@ Recurring date sequence generator.
14
14
  ```ruby
15
15
  # running on 20th of June, 2014
16
16
  > factory = Upcoming::Factory.every(:last_day_of_month)
17
- => #<Upcoming::Factory:0xb82fb490 @options={:from=>#<Date: 2014-06-20 ((2456829j,0s,0n),+0s,2299161j)>}, @chain=[#<Upcoming::LastDayOfMonthGenerator:0xb82fb094>]>
17
+ => #<Upcoming::Factory:0xb8ba6838 @options={:from=>#<Date: 2014-06-20 ((2456829j,0s,0n),+0s,2299161j)>},
18
+ @chain=[#<Upcoming::LastDayOfMonthGenerator:0xb8ba6310 @choose=:first>]>
18
19
 
19
20
  > factory.first
20
21
  => #<Date: 2014-06-30 ((2456839j,0s,0n),+0s,2299161j)>
21
22
 
22
23
  > factory.take(12).map(&:iso8601)
23
- => ["2014-06-30", "2014-07-31", "2014-08-31", "2014-09-30", "2014-10-31", "2014-11-30", "2014-12-31", "2015-01-31", "2015-02-28", "2015-03-31", "2015-04-30", "2015-05-31"]
24
+ => ["2014-06-30", "2014-07-31", "2014-08-31", "2014-09-30", "2014-10-31", "2014-11-30",
25
+ "2014-12-31", "2015-01-31", "2015-02-28", "2015-03-31", "2015-04-30", "2015-05-31"]
24
26
  ```
25
27
 
26
- It is possible to chain methods together. Running sequentially, the methods will first test whether the date given for them is valid and if it is not, alter the previous result. Any number of chains can be added.
28
+ It is possible to chain methods together. Any number of chains can be added.
29
+
30
+ Chaining forward in time is done via `then_find_upcoming`:
31
+
32
+ ```ruby
33
+ > Upcoming::Factory.every(:last_day_of_month).then_find_upcoming(:working_day).take(12).map(&:iso8601)
34
+ => ["2014-06-30", "2014-07-31", "2014-09-01", "2014-09-30", "2014-10-31", "2014-12-01",
35
+ "2014-12-31", "2015-02-02", "2015-03-02", "2015-03-31", "2015-04-30", "2015-06-01"]
36
+ ```
37
+
38
+ Stepping backwards in time is done via `then_find_preceding`:
27
39
 
28
40
  ```ruby
29
- > factory.then_find_first(:working_day).take(12).map(&:iso8601)
30
- => ["2014-06-30", "2014-07-31", "2014-09-01", "2014-09-30", "2014-10-31", "2014-12-01", "2014-12-31", "2015-02-02", "2015-03-02", "2015-03-31", "2015-04-30", "2015-06-01"]
41
+ > Upcoming::Factory.every(:last_day_of_month, from: '2014-08-20').then_find_preceding(:working_day).first
42
+ => #<Date: 2014-08-29 ((2456899j,0s,0n),+0s,2299161j)>
31
43
  ```
32
44
 
33
- Chaining backwards:
45
+ Chaining the same method has no effect:
34
46
 
35
47
  ```ruby
36
- > Upcoming::Factory.every(:last_day_of_month, from: '2014-08-20').then_find_latest(:working_day).first
37
- => 2014-08-29
48
+ Upcoming::Factory.every(:last_day_of_month, from: '2014-06-20')
49
+ .then_find_upcoming(:working_day)
50
+ .take(3).map(&:iso8601)
51
+ => ["2014-06-30", "2014-07-31", "2014-09-01"]
52
+
53
+ Upcoming::Factory.every(:last_day_of_month, from: '2014-06-20')
54
+ .then_find_upcoming(:working_day)
55
+ .then_find_upcoming(:working_day)
56
+ .then_find_upcoming(:working_day)
57
+ .take(3).map(&:iso8601)
58
+ => ["2014-06-30", "2014-07-31", "2014-09-01"]
38
59
  ```
39
60
 
40
61
  ## Generators
@@ -11,16 +11,16 @@ module Upcoming
11
11
  end
12
12
 
13
13
  def self.every(method, options = {})
14
- new(options).then_find_first(method)
14
+ new(options).then_find_upcoming(method)
15
15
  end
16
16
 
17
- def then_find_first(method)
18
- @chain << create_generator(method, :first)
17
+ def then_find_upcoming(method)
18
+ @chain << create_generator(method, :upcoming)
19
19
  self
20
20
  end
21
21
 
22
- def then_find_latest(method)
23
- @chain << create_generator(method, :latest)
22
+ def then_find_preceding(method)
23
+ @chain << create_generator(method, :preceding)
24
24
  self
25
25
  end
26
26
 
@@ -51,6 +51,5 @@ module Upcoming
51
51
  generator_class = Upcoming.const_get class_name
52
52
  generator_class.new(choose: direction)
53
53
  end
54
-
55
54
  end
56
55
  end
@@ -1,12 +1,9 @@
1
- require 'active_support/core_ext/string'
2
-
3
1
  module Upcoming
4
2
  class Generator
5
-
6
3
  attr_reader :choose
7
4
 
8
5
  def initialize(options = {})
9
- @choose = options.fetch(:choose, :first)
6
+ @choose = options.fetch(:choose, :upcoming)
10
7
  end
11
8
 
12
9
  def step(from)
@@ -16,9 +13,8 @@ module Upcoming
16
13
  private
17
14
 
18
15
  def date_range(date)
19
- return date.downto(date.prev_year) if choose == :latest
16
+ return date.downto(date.prev_year) if choose == :preceding
20
17
  date.upto(date.next_year)
21
18
  end
22
-
23
19
  end
24
20
  end
@@ -1,3 +1,3 @@
1
1
  module Upcoming
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Upcoming::Factory do
4
-
5
4
  class Upcoming::FizzGenerator < Upcoming::Generator
6
5
  def valid?(date)
7
6
  date.day % 3 == 0
@@ -67,23 +66,22 @@ describe Upcoming::Factory do
67
66
  end
68
67
 
69
68
  context 'chains do not alter main sequence' do
70
- Given(:subject) { Upcoming::Factory.every(:buzz).then_find_latest(:month_ago_if_twenty_fifth) }
69
+ Given(:subject) { Upcoming::Factory.every(:buzz).then_find_preceding(:month_ago_if_twenty_fifth) }
71
70
  Then { result == %w(2014-06-20 2014-05-25 2014-06-30) }
72
71
  end
73
72
 
74
- context '#then_find_first' do
73
+ context '#then_find_upcoming' do
75
74
  context 'modifies date found by moving to the next date that is a match' do
76
- Given(:subject) { Upcoming::Factory.every(:buzz).then_find_first(:fizz) }
75
+ Given(:subject) { Upcoming::Factory.every(:buzz).then_find_upcoming(:fizz) }
77
76
  Then { result == %w(2014-06-21 2014-06-27 2014-06-30) }
78
77
  end
79
78
  end
80
79
 
81
- context '#then_find_latest' do
80
+ context '#then_find_preceding' do
82
81
  context 'modifies date found by moving to the previous date that is a match' do
83
- Given(:subject) { Upcoming::Factory.every(:buzz).then_find_latest(:fizz) }
82
+ Given(:subject) { Upcoming::Factory.every(:buzz).then_find_preceding(:fizz) }
84
83
  Then { result == %w(2014-06-18 2014-06-24 2014-06-30) }
85
84
  end
86
85
  end
87
86
  end
88
-
89
87
  end
@@ -1,14 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Upcoming::Generator do
4
-
5
4
  class Upcoming::FakeGenerator < Upcoming::Generator
6
5
  def initialize(options = {})
7
6
  super
8
7
  @valid_dates = {}
9
8
  end
10
9
 
11
- def make_valid(date)
10
+ def mark_as_valid(date)
12
11
  @valid_dates[Date.parse(date)] = true
13
12
  end
14
13
 
@@ -22,18 +21,22 @@ describe Upcoming::Generator do
22
21
  result and result.iso8601
23
22
  end
24
23
 
25
- Given(:subject) { Upcoming::FakeGenerator.new }
26
-
27
- context 'returns the same date if it is valid' do
28
- Given(:start_date) { '2014-05-19' }
29
- When { subject.make_valid(start_date) }
30
- Then { step(start_date) == start_date }
24
+ def self.returns_the_starting_date_if_it_is_valid
25
+ context 'returns the starting date if it is valid' do
26
+ Given(:start_date) { '2014-05-19' }
27
+ When { subject.mark_as_valid(start_date) }
28
+ Then { step(start_date) == start_date }
29
+ end
31
30
  end
32
31
 
33
32
  context 'forward in time' do
33
+ Given(:subject) { Upcoming::FakeGenerator.new(choose: :upcoming) }
34
+
35
+ returns_the_starting_date_if_it_is_valid
36
+
34
37
  context 'returns the first valid date, checking all dates in sequence' do
35
- When { subject.make_valid('2014-05-20') }
36
- When { subject.make_valid('2014-06-20') }
38
+ When { subject.mark_as_valid('2014-05-20') }
39
+ When { subject.mark_as_valid('2014-06-20') }
37
40
  Then { step('2014-05-19') == '2014-05-20' }
38
41
  Then { step('2014-05-21') == '2014-06-20' }
39
42
  Then { step('2014-06-10') == '2014-06-20' }
@@ -41,18 +44,20 @@ describe Upcoming::Generator do
41
44
 
42
45
  context 'returns nil if there is no valid date within 1 year' do
43
46
  # implement a custom +step+ method in your generator if you need this
44
- When { subject.make_valid('2020-01-01') }
47
+ When { subject.mark_as_valid('2020-01-01') }
45
48
  Then { step('2018-12-31') == nil }
46
49
  Then { step('2019-01-01') == '2020-01-01' }
47
50
  end
48
51
  end
49
52
 
50
53
  context 'backward in time' do
51
- Given(:subject) { Upcoming::FakeGenerator.new(choose: :latest) }
54
+ Given(:subject) { Upcoming::FakeGenerator.new(choose: :preceding) }
55
+
56
+ returns_the_starting_date_if_it_is_valid
52
57
 
53
58
  context 'returns the closest past date, checking all dates in sequence' do
54
- When { subject.make_valid('2010-03-04') }
55
- When { subject.make_valid('2010-09-21') }
59
+ When { subject.mark_as_valid('2010-03-04') }
60
+ When { subject.mark_as_valid('2010-09-21') }
56
61
  Then { step('2010-09-22') == '2010-09-21' }
57
62
  Then { step('2010-09-20') == '2010-03-04' }
58
63
  Then { step('2010-06-01') == '2010-03-04' }
@@ -60,10 +65,9 @@ describe Upcoming::Generator do
60
65
 
61
66
  context 'returns nil if there is no valid date within -1 year' do
62
67
  # implement a custom +step+ method in your generator if you need this
63
- When { subject.make_valid('2010-01-01') }
68
+ When { subject.mark_as_valid('2010-01-01') }
64
69
  Then { step('2011-01-02') == nil }
65
70
  Then { step('2011-01-01') == '2010-01-01' }
66
71
  end
67
72
  end
68
-
69
73
  end
@@ -1,23 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Upcoming::LastDayOfMonthGenerator do
4
-
5
4
  Given(:subject) { Upcoming::LastDayOfMonthGenerator.new }
6
5
  When(:valid) { subject.valid?(date) }
7
6
 
8
- context 'not valid on not last day of month' do
7
+ context 'start of the month is invalid' do
8
+ Given(:date) { Date.parse('2014-06-01') }
9
+ Then { !valid }
10
+ end
11
+
12
+ context 'middle of the month is invalid' do
9
13
  Given(:date) { Date.parse('2014-06-15') }
10
14
  Then { !valid }
11
15
  end
12
16
 
13
- context 'valid on last day of month' do
17
+ context 'last day of the month is valid' do
14
18
  Given(:date) { Date.parse('2014-05-31') }
15
19
  Then { valid }
16
20
  end
17
21
 
18
- context 'valid on leap day' do
22
+ context 'last day of February in a leap year is valid' do
19
23
  Given(:date) { Date.parse('2012-02-29') }
20
24
  Then { valid }
21
25
  end
22
-
23
26
  end
@@ -1,10 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Upcoming::WorkingDayGenerator do
4
-
5
4
  Given(:subject) { Upcoming::WorkingDayGenerator.new }
6
5
 
7
- context 'returns invalid for weekends' do
6
+ context 'weekends are invalid' do
8
7
  Given(:saturday) { Date.parse('2014-06-14') }
9
8
  Given(:sunday) { Date.parse('2014-06-15') }
10
9
 
@@ -12,7 +11,7 @@ describe Upcoming::WorkingDayGenerator do
12
11
  Then { !subject.valid?(sunday) }
13
12
  end
14
13
 
15
- context 'returns next workday when given workday' do
14
+ context 'weekdays are valid' do
16
15
  Given(:monday) { Date.parse('2014-06-16') }
17
16
  Given(:tuesday) { monday + 1 }
18
17
  Given(:wednesday) { tuesday + 1 }
@@ -25,5 +24,4 @@ describe Upcoming::WorkingDayGenerator do
25
24
  Then { subject.valid?(thursday) }
26
25
  Then { subject.valid?(friday) }
27
26
  end
28
-
29
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upcoming
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
  - David Lantos
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-26 00:00:00.000000000 Z
11
+ date: 2016-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.1'
19
+ version: '5.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.1'
26
+ version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -87,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 1.9.3
90
+ version: 2.2.2
91
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.2
98
+ rubygems_version: 2.5.1
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Recurring date generator