blackcal 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +11 -0
- data/README.md +10 -9
- data/lib/blackcal/{day_range.rb → range/day_range.rb} +0 -0
- data/lib/blackcal/range/month_range.rb +44 -0
- data/lib/blackcal/{time_of_day_range.rb → range/time_of_day_range.rb} +0 -0
- data/lib/blackcal/{time_range.rb → range/time_range.rb} +0 -0
- data/lib/blackcal/{weekday_range.rb → range/weekday_range.rb} +0 -0
- data/lib/blackcal/schedule.rb +9 -5
- data/lib/blackcal/version.rb +1 -1
- data/lib/blackcal.rb +6 -0
- metadata +7 -6
- data/Gemfile.lock +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c23e691a5c3523795779efef15fe053f74136c0f0c1ce61acd8a57f8b988f761
|
4
|
+
data.tar.gz: 631199640ed9b4af0c913ae4a8b6c54ec11d5b3098996dcc0dedcac7dfb3c1e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15d610fec732303f9ea7badd1f8139298cb1161bdabf1baf6cee2c355a11cd826f3544747e7baa9159afed3818e83ae06d7fa32a68df7a4612c573e7daa49e27
|
7
|
+
data.tar.gz: 1792395fc246472ca622b39920c67f5829d911f1431c8853c1697ab7d380fba6bc278af3a4c24c21f73d579d6019e3f89f2b58c6bef5eefa8299513944f474f0
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -22,16 +22,16 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
Schedule Mondays and Tuesdays
|
24
24
|
```ruby
|
25
|
-
schedule = Blackcal
|
25
|
+
schedule = Blackcal.schedule(weekdays: [:monday, :tuesday])
|
26
26
|
schedule.cover?('2019-01-01 19:00')
|
27
27
|
# => false
|
28
28
|
schedule.cover?('2019-01-02 11:00')
|
29
29
|
# => true
|
30
30
|
```
|
31
31
|
|
32
|
-
Schedule between
|
32
|
+
Schedule between 6pm and 7am every day
|
33
33
|
```ruby
|
34
|
-
schedule = Blackcal
|
34
|
+
schedule = Blackcal.schedule(start_hour: 18, finish_hour: 7)
|
35
35
|
schedule.cover?('2019-01-01 19:00')
|
36
36
|
# => false
|
37
37
|
schedule.cover?('2019-01-01 11:00')
|
@@ -40,34 +40,35 @@ schedule.cover?('2019-01-01 11:00')
|
|
40
40
|
|
41
41
|
Schedule day 15 and 17 of month
|
42
42
|
```ruby
|
43
|
-
schedule = Blackcal
|
43
|
+
schedule = Blackcal.schedule(days: [15, 17])
|
44
44
|
schedule.cover?('2019-01-15 19:00')
|
45
45
|
# => false
|
46
46
|
schedule.cover?('2019-01-01 11:00')
|
47
47
|
# => true
|
48
48
|
```
|
49
49
|
|
50
|
-
All options at once - schedule Tuesdays, day 15-25, between 18pm and 7am
|
50
|
+
All options at once - schedule January, Mondays and Tuesdays, day 15-25, between 18pm and 7am
|
51
51
|
```ruby
|
52
|
-
schedule = Blackcal
|
52
|
+
schedule = Blackcal.schedule(
|
53
|
+
months: [:january],
|
53
54
|
weekdays: [:monday, :tuesday],
|
54
55
|
start_hour: 18, finish_hour: 7,
|
55
56
|
days: (15..25).to_a
|
56
57
|
)
|
57
58
|
schedule.cover?('2019-01-15 19:00')
|
58
59
|
# => false
|
59
|
-
schedule.cover?('2019-
|
60
|
+
schedule.cover?('2019-02-01 11:00')
|
60
61
|
# => true
|
61
62
|
```
|
62
63
|
|
63
64
|
Define when the schedule is active
|
64
65
|
```ruby
|
65
|
-
Blackcal
|
66
|
+
Blackcal.schedule(start_time: '2018-01-01 11:00', finish_time: '2019-01-01 11:00')
|
66
67
|
```
|
67
68
|
|
68
69
|
Matrix representation
|
69
70
|
```ruby
|
70
|
-
schedule = Blackcal
|
71
|
+
schedule = Blackcal.schedule(weekdays: :friday, start_hour: 10, finish_hour: 14)
|
71
72
|
schedule.to_matrix(start_date: '2018-09-14', finish_date: '2018-09-16')
|
72
73
|
# => [[true, ...], [true, ...]]
|
73
74
|
```
|
File without changes
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Blackcal
|
4
|
+
# Month range
|
5
|
+
class MonthRange
|
6
|
+
MONTH_MAP = {
|
7
|
+
january: 1,
|
8
|
+
february: 2,
|
9
|
+
march: 3,
|
10
|
+
april: 4,
|
11
|
+
may: 5,
|
12
|
+
june: 6,
|
13
|
+
july: 7,
|
14
|
+
august: 8,
|
15
|
+
september: 9,
|
16
|
+
october: 10,
|
17
|
+
november: 11,
|
18
|
+
december: 12,
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
# @return [Array<Symbol>] months in range
|
22
|
+
attr_reader :months
|
23
|
+
|
24
|
+
# Initialize month range
|
25
|
+
# @param [Array<String>, Array<Symbol>, String, Symbol, nil] months
|
26
|
+
# @example
|
27
|
+
# MonthRange.new(:january)
|
28
|
+
# @example
|
29
|
+
# MonthRange.new([:december, :january])
|
30
|
+
def initialize(months)
|
31
|
+
@months = Array(months).map(&:to_sym) if months
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns true if it covers timestamp
|
35
|
+
# @return [Boolean]
|
36
|
+
def cover?(timestamp)
|
37
|
+
return false if @months.nil? || @months.empty?
|
38
|
+
|
39
|
+
months.any? do |month|
|
40
|
+
MONTH_MAP.fetch(month) == timestamp.month
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
data/lib/blackcal/schedule.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
require 'time'
|
4
4
|
|
5
|
-
require 'blackcal/time_range'
|
6
|
-
require 'blackcal/time_of_day_range'
|
7
|
-
require 'blackcal/weekday_range'
|
8
|
-
require 'blackcal/
|
5
|
+
require 'blackcal/range/time_range'
|
6
|
+
require 'blackcal/range/time_of_day_range'
|
7
|
+
require 'blackcal/range/weekday_range'
|
8
|
+
require 'blackcal/range/month_range'
|
9
|
+
require 'blackcal/range/day_range'
|
9
10
|
require 'blackcal/slot_matrix'
|
10
11
|
|
11
12
|
module Blackcal
|
@@ -16,6 +17,7 @@ module Blackcal
|
|
16
17
|
# @param finish_time [Time, Date, String, nil]
|
17
18
|
# @param start_hour [Integer, nil]
|
18
19
|
# @param finish_hour [Integer, nil]
|
20
|
+
# @param months [Array<String>, Array<Symbol>, String, Symbol, nil]
|
19
21
|
# @param weekdays [Array<String>, Array<Symbol>, String, Symbol, nil]
|
20
22
|
# @param days [Array<Integer>, Integer, nil]
|
21
23
|
def initialize(
|
@@ -23,12 +25,14 @@ module Blackcal
|
|
23
25
|
finish_time: nil,
|
24
26
|
start_hour: nil,
|
25
27
|
finish_hour: nil,
|
28
|
+
months: nil,
|
26
29
|
weekdays: nil,
|
27
30
|
# weeks_of_month: nil, # TODO
|
28
31
|
days: nil
|
29
32
|
)
|
30
33
|
@rule_range = TimeRange.new(parse_time(start_time), parse_time(finish_time)) if start_time || finish_time # rubocop:disable Metrics/LineLength
|
31
34
|
@time_of_day = TimeOfDayRange.new(start_hour, finish_hour) if start_hour || finish_hour # rubocop:disable Metrics/LineLength
|
35
|
+
@months = MonthRange.new(months) if months
|
32
36
|
@weekdays = WeekdayRange.new(weekdays) if weekdays
|
33
37
|
@days = DayRange.new(days) if days
|
34
38
|
end
|
@@ -40,7 +44,7 @@ module Blackcal
|
|
40
44
|
timestamp = parse_time(timestamp)
|
41
45
|
return true if @rule_range && !@rule_range.cover?(timestamp)
|
42
46
|
|
43
|
-
[@weekdays, @days, @time_of_day].each do |range|
|
47
|
+
[@months, @weekdays, @days, @time_of_day].each do |range|
|
44
48
|
return true if range && !range.cover?(timestamp)
|
45
49
|
end
|
46
50
|
|
data/lib/blackcal/version.rb
CHANGED
data/lib/blackcal.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackcal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Burenstam
|
@@ -79,8 +79,8 @@ files:
|
|
79
79
|
- ".rubocop.yml"
|
80
80
|
- ".ruby-style-guide.yml"
|
81
81
|
- ".travis.yml"
|
82
|
+
- CHANGELOG.md
|
82
83
|
- Gemfile
|
83
|
-
- Gemfile.lock
|
84
84
|
- LICENSE.txt
|
85
85
|
- README.md
|
86
86
|
- Rakefile
|
@@ -88,13 +88,14 @@ files:
|
|
88
88
|
- bin/setup
|
89
89
|
- blackcal.gemspec
|
90
90
|
- lib/blackcal.rb
|
91
|
-
- lib/blackcal/day_range.rb
|
91
|
+
- lib/blackcal/range/day_range.rb
|
92
|
+
- lib/blackcal/range/month_range.rb
|
93
|
+
- lib/blackcal/range/time_of_day_range.rb
|
94
|
+
- lib/blackcal/range/time_range.rb
|
95
|
+
- lib/blackcal/range/weekday_range.rb
|
92
96
|
- lib/blackcal/schedule.rb
|
93
97
|
- lib/blackcal/slot_matrix.rb
|
94
|
-
- lib/blackcal/time_of_day_range.rb
|
95
|
-
- lib/blackcal/time_range.rb
|
96
98
|
- lib/blackcal/version.rb
|
97
|
-
- lib/blackcal/weekday_range.rb
|
98
99
|
homepage: https://github.com/buren/blackcal
|
99
100
|
licenses:
|
100
101
|
- MIT
|
data/Gemfile.lock
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
blackcal (0.1.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
byebug (10.0.2)
|
10
|
-
diff-lcs (1.3)
|
11
|
-
rake (10.5.0)
|
12
|
-
rspec (3.8.0)
|
13
|
-
rspec-core (~> 3.8.0)
|
14
|
-
rspec-expectations (~> 3.8.0)
|
15
|
-
rspec-mocks (~> 3.8.0)
|
16
|
-
rspec-core (3.8.0)
|
17
|
-
rspec-support (~> 3.8.0)
|
18
|
-
rspec-expectations (3.8.1)
|
19
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
-
rspec-support (~> 3.8.0)
|
21
|
-
rspec-mocks (3.8.0)
|
22
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
-
rspec-support (~> 3.8.0)
|
24
|
-
rspec-support (3.8.0)
|
25
|
-
|
26
|
-
PLATFORMS
|
27
|
-
ruby
|
28
|
-
|
29
|
-
DEPENDENCIES
|
30
|
-
blackcal!
|
31
|
-
bundler (~> 1.16)
|
32
|
-
byebug
|
33
|
-
rake (~> 10.0)
|
34
|
-
rspec (~> 3.0)
|
35
|
-
|
36
|
-
BUNDLED WITH
|
37
|
-
1.16.2
|