repeatable 0.4.0 → 0.5.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: 49614dbb77808403fec7ce7b17f8e6b4c5c6ee99
4
- data.tar.gz: 19759e4931d334759c54f6a80c9856fe92bc01e3
3
+ metadata.gz: 7810dbdca8bf11e8e30101cc1bd22afbcaf698a0
4
+ data.tar.gz: e1408eb13dbf184b1115d90ae814db6582b0a640
5
5
  SHA512:
6
- metadata.gz: 89a121c2ecf46fbb6cd89bf150a00dff53452fa2cbfddaf4bff89255455f7bab86aa09d50ea0e5a4d60de7306f70096657dfb2f63a59b2092aa2fe5bb9bb149c
7
- data.tar.gz: f0c55a63c03e9055b40cc90183ad176eb75027411a71de000a4f95c0f57a6dd85b9ee98a4c581539475c9712fb08f4e59c13f765b3711abb9b2c5719ecf65416
6
+ metadata.gz: ebd63d839565ebe7971e5566462dad20d851a9a110eee829d1f53ec8868559fa6b46f14c8528e067827daa95da6e9929a479ca852d69e54884b4a6c071a3b139
7
+ data.tar.gz: b623c8e4040e6a8276f86c7b71078019fb830dd2ff88b0d5e784618580350cd5b8c51e45ce3846126765a97a1c448ea3e9d9d1f2261ded030cb7ad7ee195dcab
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.0
4
- - 2.2.0
3
+ - 2.1.8
4
+ - 2.2.4
5
+ - 2.3.0
6
+ sudo: false
5
7
  addons:
6
8
  code_climate:
7
9
  repo_token:
data/CHANGELOG.md CHANGED
@@ -2,7 +2,15 @@
2
2
 
3
3
  ### Unreleased
4
4
 
5
- [Commits](https://github.com/molawson/repeatable/compare/v0.4.0...master)
5
+ [Commits](https://github.com/molawson/repeatable/compare/v0.5.0...master)
6
+
7
+ ### 0.5.0 (2016-01-27)
8
+
9
+ Features:
10
+
11
+ * Add `Expression::Biweekly` for "every other week" recurrence
12
+
13
+ [Commits](https://github.com/molawson/repeatable/compare/v0.4.0...v0.5.0)
6
14
 
7
15
  ### 0.4.0 (2015-06-29)
8
16
 
data/README.md CHANGED
@@ -84,6 +84,10 @@ Repeatable::Expression::Weekday.new(weekday: 0)
84
84
  { weekday_in_month: { weekday: 1, count: 3 } }
85
85
  Repeatable::Expression::WeekdayInMonth.new(weekday: 1, count: 3)
86
86
 
87
+ # Every other Monday, starting from December 1, 2015
88
+ { biweekly: { weekday: 1, start_date: '2015-12-01' } }
89
+ Repeatable::Expression::Biweekly.new(weekday: 1, start_date: Date.new(2015, 12, 1))
90
+
87
91
  # The 13th of every month
88
92
  { day_in_month: { day: 13 } }
89
93
  Repeatable::Expression::DayInMonth.new(day: 13)
@@ -0,0 +1,28 @@
1
+ module Repeatable
2
+ module Expression
3
+ class Biweekly < Date
4
+ def initialize(weekday:, start_after: ::Date.today)
5
+ @weekday = weekday
6
+ @start_after = Date(start_after)
7
+ end
8
+
9
+ def include?(date)
10
+ date >= start_after && (date - first_occurrence) % 14 == 0
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :weekday, :start_after
16
+
17
+ def first_occurrence
18
+ @first_occurrence ||= find_first_occurrence
19
+ end
20
+
21
+ def find_first_occurrence
22
+ days_away = weekday - start_after.wday
23
+ days_away += 7 if days_away <= 0
24
+ start_after + days_away
25
+ end
26
+ end
27
+ end
28
+ end
@@ -19,7 +19,19 @@ module Repeatable
19
19
  protected
20
20
 
21
21
  def attributes
22
- Hash[instance_variables.map { |name| [name[1..-1].to_sym, instance_variable_get(name)] }]
22
+ instance_variables.each_with_object({}) do |name, hash|
23
+ key = name.to_s.gsub(/^@/, '').to_sym
24
+ hash[key] = normalize_attribute_value(instance_variable_get(name))
25
+ end
26
+ end
27
+
28
+ def normalize_attribute_value(value)
29
+ case value
30
+ when ::Date
31
+ value.to_s
32
+ else
33
+ value
34
+ end
23
35
  end
24
36
  end
25
37
  end
@@ -1,3 +1,3 @@
1
1
  module Repeatable
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/repeatable.rb CHANGED
@@ -15,6 +15,7 @@ require 'repeatable/expression/base'
15
15
 
16
16
  require 'repeatable/expression/date'
17
17
  require 'repeatable/expression/weekday'
18
+ require 'repeatable/expression/biweekly'
18
19
  require 'repeatable/expression/weekday_in_month'
19
20
  require 'repeatable/expression/day_in_month'
20
21
  require 'repeatable/expression/range_in_year'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repeatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mo Lawson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2016-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,6 +74,7 @@ files:
74
74
  - lib/repeatable/conversions.rb
75
75
  - lib/repeatable/expression.rb
76
76
  - lib/repeatable/expression/base.rb
77
+ - lib/repeatable/expression/biweekly.rb
77
78
  - lib/repeatable/expression/date.rb
78
79
  - lib/repeatable/expression/day_in_month.rb
79
80
  - lib/repeatable/expression/intersection.rb