timeboss 1.1.0 → 1.1.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
  SHA256:
3
- metadata.gz: 3091d788f78273741aeb0206a87765fed72e3908099c2596b70589740aa63c26
4
- data.tar.gz: 2a0cd5b28cc9b05c07d3fe06aef86644876864b7b24eda946105706d0626622f
3
+ metadata.gz: 65f9e2cd955a728e0efd00e99f530f1ff6dbb7ee0c8cee7e25499466fb10edc9
4
+ data.tar.gz: 9523e2983ffff0d5d33cf9b07e7fd4cd1b26b54c68e8a3f77d8996aaa7ad991d
5
5
  SHA512:
6
- metadata.gz: f58a6f56a3bf0cb2f44a00aee3b5a4d09fdbcd4b2cd8b06c2942fa4eefc508b0afff19dd577bef26bd7b5f187ca1ccb380e5efdd5b357da829ad2936d36c12ff
7
- data.tar.gz: 5f2b1b5013f49c81e3e5f9066e9e4c3063ddd70231a7199010a79b822bc3531ead0d0bf285d9d045fb0434dcfa6e0a5564aac138a8b25b07e2a374b1c049faf9
6
+ metadata.gz: 1f850961e4659cee0b07e59d4421f1444c39e3882338f5189cd5821e5d4ec00228c4043aef7c001df8a2181cf4161671943653e7e0c843f419f4f7d91b6bb99d
7
+ data.tar.gz: 24a8f28844c20caf7f0294a5e5db155ff809f46ad76e421e97d807b929ceca37035d9b89539a5600713d9420ba8f799fa1668c61e47b040a8728c41df12a67df
data/bin/tbsh CHANGED
@@ -1,13 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'timeboss/calendars'
4
- require 'shellable'
3
+ require "timeboss"
4
+ require "timeboss/calendars"
5
+ require "shellable"
5
6
 
6
7
  calendar = if ARGV.length == 1
7
- TimeBoss::Calendars[ARGV.first]
8
- else
9
- TimeBoss::Calendars.first.calendar
10
- end
8
+ TimeBoss::Calendars[ARGV.first]
9
+ else
10
+ TimeBoss::Calendars.first.calendar
11
+ end
11
12
 
12
13
  abort "Unknown calendar" if calendar.nil?
13
14
 
@@ -84,6 +84,15 @@ module TimeBoss
84
84
  @_to_range ||= start_date..end_date
85
85
  end
86
86
 
87
+ # Clamp this unit to the range of the provided unit.
88
+ # @return [Period]
89
+ def clamp(unit)
90
+ new_start_date = start_date.clamp(unit.start_date, unit.end_date)
91
+ new_end_date = end_date.clamp(unit.start_date, unit.end_date)
92
+ return unless new_start_date.between?(start_date, end_date) && new_end_date.between?(start_date, end_date)
93
+ calendar.parse("#{new_start_date}..#{new_end_date}")
94
+ end
95
+
87
96
  def inspect
88
97
  "#<#{self.class.name} start_date=#{start_date}, end_date=#{end_date}>"
89
98
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TimeBoss
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.3"
5
5
  end
data/lib/timeboss.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/isolated_execution_state"
3
+ require "active_support"
4
4
  require "timeboss/version"
5
5
 
6
6
  # TimeBoss
@@ -28,6 +28,57 @@ module TimeBoss
28
28
  end
29
29
  end
30
30
 
31
+ describe "#clamp" do
32
+ let(:clamp_start_date) { Date.parse("2018-06-21") }
33
+ let(:clamp_end_date) { Date.parse("2018-08-30") }
34
+ let(:result) { subject.clamp(described_class.new(calendar, clamp_start_date, clamp_end_date)) }
35
+ let(:period) { double }
36
+
37
+ context "open" do
38
+ it "does not restrict the returned period" do
39
+ expect(calendar).to receive(:parse).with("#{start_date}..#{end_date}").and_return period
40
+ expect(result).to eq period
41
+ end
42
+ end
43
+
44
+ context "left clamped" do
45
+ let(:clamp_start_date) { Date.parse("2018-06-30") }
46
+
47
+ it "brings the beginning date inward" do
48
+ expect(calendar).to receive(:parse).with("#{clamp_start_date}..#{end_date}").and_return period
49
+ expect(result).to eq period
50
+ end
51
+ end
52
+
53
+ context "right clamped" do
54
+ let(:clamp_end_date) { Date.parse("2018-07-30") }
55
+
56
+ it "brings the beginning date inward" do
57
+ expect(calendar).to receive(:parse).with("#{start_date}..#{clamp_end_date}").and_return period
58
+ expect(result).to eq period
59
+ end
60
+ end
61
+
62
+ context "fully clamped" do
63
+ let(:clamp_start_date) { Date.parse("2018-06-30") }
64
+ let(:clamp_end_date) { Date.parse("2018-07-30") }
65
+
66
+ it "brings the beginning date inward" do
67
+ expect(calendar).to receive(:parse).with("#{clamp_start_date}..#{clamp_end_date}").and_return period
68
+ expect(result).to eq period
69
+ end
70
+ end
71
+
72
+ context "obliterated" do
73
+ let(:clamp_start_date) { Date.parse("2018-09-01") }
74
+ let(:clamp_end_date) { Date.parse("2018-09-06") }
75
+
76
+ it "returns nil" do
77
+ expect(result).to be_nil
78
+ end
79
+ end
80
+ end
81
+
31
82
  context "periods" do
32
83
  before(:each) do
33
84
  allow(calendar).to receive(:days_for).with(subject).and_return %w[D1 D2 D3 D4 D5 D6 D7 D8]
data/timeboss.gemspec CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency "activesupport"
23
23
 
24
+ spec.add_runtime_dependency "shellable"
25
+
24
26
  spec.add_development_dependency "bundler"
25
27
  spec.add_development_dependency "pry"
26
28
  spec.add_development_dependency "pry-byebug"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeboss
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McDonald
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-17 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: shellable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -201,14 +215,14 @@ files:
201
215
  - lib/timeboss/calendars/broadcast.rb
202
216
  - lib/timeboss/calendars/gregorian.rb
203
217
  - lib/timeboss/version.rb
204
- - spec/calendar/day_spec.rb
205
- - spec/calendar/quarter_spec.rb
206
- - spec/calendar/support/monthly_unit_spec.rb
207
- - spec/calendar/support/unit_spec.rb
208
- - spec/calendar/week_spec.rb
209
- - spec/calendars/broadcast_spec.rb
210
- - spec/calendars/gregorian_spec.rb
211
- - spec/calendars_spec.rb
218
+ - spec/lib/timeboss/calendar/day_spec.rb
219
+ - spec/lib/timeboss/calendar/quarter_spec.rb
220
+ - spec/lib/timeboss/calendar/support/monthly_unit_spec.rb
221
+ - spec/lib/timeboss/calendar/support/unit_spec.rb
222
+ - spec/lib/timeboss/calendar/week_spec.rb
223
+ - spec/lib/timeboss/calendars/broadcast_spec.rb
224
+ - spec/lib/timeboss/calendars/gregorian_spec.rb
225
+ - spec/lib/timeboss/calendars_spec.rb
212
226
  - spec/spec_helper.rb
213
227
  - timeboss.gemspec
214
228
  homepage: https://github.com/kevinstuffandthings/timeboss
@@ -235,12 +249,12 @@ signing_key:
235
249
  specification_version: 4
236
250
  summary: Broadcast Calendar navigation in Ruby made simple
237
251
  test_files:
238
- - spec/calendar/day_spec.rb
239
- - spec/calendar/quarter_spec.rb
240
- - spec/calendar/support/monthly_unit_spec.rb
241
- - spec/calendar/support/unit_spec.rb
242
- - spec/calendar/week_spec.rb
243
- - spec/calendars/broadcast_spec.rb
244
- - spec/calendars/gregorian_spec.rb
245
- - spec/calendars_spec.rb
252
+ - spec/lib/timeboss/calendar/day_spec.rb
253
+ - spec/lib/timeboss/calendar/quarter_spec.rb
254
+ - spec/lib/timeboss/calendar/support/monthly_unit_spec.rb
255
+ - spec/lib/timeboss/calendar/support/unit_spec.rb
256
+ - spec/lib/timeboss/calendar/week_spec.rb
257
+ - spec/lib/timeboss/calendars/broadcast_spec.rb
258
+ - spec/lib/timeboss/calendars/gregorian_spec.rb
259
+ - spec/lib/timeboss/calendars_spec.rb
246
260
  - spec/spec_helper.rb