kalendor 0.0.4 → 0.0.5

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
- SHA1:
3
- metadata.gz: 8233c57889dc42f00dbd60c1710b90cfebbf9ac7
4
- data.tar.gz: d1c5696401d654c0391a3e846439540255f4cf4d
2
+ SHA256:
3
+ metadata.gz: 8444d0694397d073104ded49efd8c0f3d67cd4a2cff9227214b35c9cc2a01b34
4
+ data.tar.gz: 488d82824e4643d8802f4a6707bd074ff74973e8c12ac14fc6c890ebcfc67565
5
5
  SHA512:
6
- metadata.gz: c313972414214c589920aeb3948fa7452ce178cd67df4aa5e122c777226f81a4cb2bf6d83370b530e153e3a41c8f1e73950b056ea9ea38caceef34e7f3dec03b
7
- data.tar.gz: fb37990fead79b1c33c5322b67281c913aad8ad0b8afa3e69031b4f2f96929492f37c86cf022bd91d619db9de8d35792dc1ae8016d28015a9bd64ced9db38d8c
6
+ metadata.gz: a9599ebca8914d341d2c94acc78461131d5aadbfa869599bad0902e045427ee2b673c6bf5bdc880ad2a5bd1badf4415af2f18f62234ad26d191cae9898364ac2
7
+ data.tar.gz: 180e1b7ed41294247dffd69ef5ed0e52ca50ef80a343398c105fde2ebe13044a58b29bc24944622f5484fb772a12876c10f850ba4e3632e455e59d0b3729a357
@@ -52,6 +52,10 @@ module Kalendor
52
52
  Kalendor::Instance::Monthly.new monthly_date: d
53
53
  end
54
54
 
55
+ def append existing, other
56
+ existing.append other
57
+ end
58
+
55
59
  def subtract? x, y ; y ? subtract(x, y) : x ; end
56
60
  alias date to_date
57
61
  end
@@ -3,4 +3,7 @@ require "kalendor/instance/composite"
3
3
 
4
4
  class Kalendor::Instance::Union < Kalendor::Instance::Composite
5
5
  include Kalendor::Union
6
+ def append other
7
+ self.class.new name: name, label: label, schedules: [other, *schedules]
8
+ end
6
9
  end
@@ -2,6 +2,23 @@ module Kalendor
2
2
  module Instance
3
3
  class Base < Aduki::Initializable
4
4
  attr_accessor :name, :label
5
+
6
+ def append other
7
+ me = self
8
+ Kalendor.build { union me, other }
9
+ end
10
+
11
+ def union *others
12
+ Kalendor::Instance::Union.new(schedules: [self, *others])
13
+ end
14
+
15
+ def intersect *others
16
+ Kalendor::Instance::Intersect.new(schedules: [self, *others])
17
+ end
18
+
19
+ def subtract other
20
+ Kalendor::Instance::Subtract.new include_dates: self, exclude_dates: other
21
+ end
5
22
  end
6
23
  end
7
24
  end
@@ -1,3 +1,3 @@
1
1
  module Kalendor
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,32 @@
1
+ require 'kalendor'
2
+ require 'kalendor/instance/annual'
3
+ require 'kalendor/instance/union'
4
+ require 'kalendor/instance/weekday'
5
+
6
+ RSpec.describe "#append" do
7
+ it "produces every weekend in oct - dec 2016" do
8
+ sats = Kalendor.build { weekday(6) }
9
+ suns = Kalendor.build { weekday(7) }
10
+
11
+ weekends = Kalendor.build { append sats, suns }
12
+
13
+ weekends_in_oct_2016 = [1,2,8,9,15,16,22,23,29,30].map { |d| date("2016-10-#{d}") }
14
+ weekends_in_nov_2016 = [5,6,12,13,19,20,26,27 ].map { |d| date("2016-11-#{d}") }
15
+ weekends_in_dec_2016 = [3,4,10,11,17,18,24,25,31 ].map { |d| date("2016-12-#{d}") }
16
+ weekends_in_end_2016 = weekends_in_oct_2016 + weekends_in_nov_2016 + weekends_in_dec_2016
17
+
18
+ expect(weekends.get_dates date("2016-10-01"), date("2016-12-31")).to eq weekends_in_end_2016
19
+ end
20
+
21
+ it "appends to a union" do
22
+ mix = Kalendor.build { union annual(12,3), annual(21,6), annual(8,6) }
23
+
24
+ more = Kalendor.build { append mix, annual(18,11) }
25
+
26
+ bd2015 = %w{ 2015-03-12 2015-06-08 2015-06-21 2015-11-18 }
27
+ bd2016 = %w{ 2016-03-12 2016-06-08 2016-06-21 2016-11-18 }
28
+ expected = (bd2015 + bd2016).map { |d| date d }.sort
29
+
30
+ expect(more.get_dates date("2015-01-01"), date("2016-12-31")).to eq expected
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kalendor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Conan Dalton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-31 00:00:00.000000000 Z
11
+ date: 2023-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aduki
@@ -121,6 +121,7 @@ files:
121
121
  - lib/kalendor/version.rb
122
122
  - lib/kalendor/weekday.rb
123
123
  - spec/annual_spec.rb
124
+ - spec/append_spec.rb
124
125
  - spec/date_list_spec.rb
125
126
  - spec/date_spec.rb
126
127
  - spec/intersect_spec.rb
@@ -151,13 +152,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  - !ruby/object:Gem::Version
152
153
  version: '0'
153
154
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.5.2.3
155
+ rubygems_version: 3.0.3.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Utility classes for generating sets of dates
159
159
  test_files:
160
160
  - spec/annual_spec.rb
161
+ - spec/append_spec.rb
161
162
  - spec/date_list_spec.rb
162
163
  - spec/date_spec.rb
163
164
  - spec/intersect_spec.rb