slotty 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +1 -0
- data/Gemfile.lock +4 -4
- data/README.md +6 -5
- data/lib/slotty.rb +24 -13
- data/lib/slotty/slot.rb +33 -0
- data/lib/slotty/timeframe.rb +20 -0
- data/lib/slotty/version.rb +1 -1
- data/slotty-0.1.0.gem +0 -0
- data/slotty.gemspec +1 -1
- metadata +10 -6
- data/lib/slotty/validator.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ce087830c3a4b050ffdf7c1b22b7421e643fd377d1a5011995c5eb8a301d649
|
4
|
+
data.tar.gz: fba230d41f3fd7732de6b871b80cc5f7509ab2d54b204eab97913f0e60bb62d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab763cbad35a6322583759c42d9b38f8d31e566ad94885b3fbbc66c16a1c2efb28059841a52e1350ce48b57f8a5d4d908cc2adba4b5790a34d98629e3e8b1b36
|
7
|
+
data.tar.gz: c05da44d9004438d64389b0954e68a0718880fd39e4b0871eeaf03ced25b727beaad3b26544e080d0e468288b28ea148e18bece6ac9ac7e30fc577be34d2c9ef
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 2.5.0
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
slotty (
|
4
|
+
slotty (1.0.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
9
|
diff-lcs (1.3)
|
10
|
-
rake (
|
10
|
+
rake (12.3.3)
|
11
11
|
rspec (3.9.0)
|
12
12
|
rspec-core (~> 3.9.0)
|
13
13
|
rspec-expectations (~> 3.9.0)
|
@@ -27,9 +27,9 @@ PLATFORMS
|
|
27
27
|
|
28
28
|
DEPENDENCIES
|
29
29
|
bundler (~> 1.17)
|
30
|
-
rake (~>
|
30
|
+
rake (~> 12.3.3)
|
31
31
|
rspec (~> 3.0)
|
32
32
|
slotty!
|
33
33
|
|
34
34
|
BUNDLED WITH
|
35
|
-
1.17.
|
35
|
+
1.17.3
|
data/README.md
CHANGED
@@ -22,12 +22,11 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
Slotty.get_slots(
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
timeframe: 15 * 60,
|
25
|
+
for_range: Time.new(2020, 05, 01, 8, 00)..Time.new(2020, 05, 01, 11, 00),
|
26
|
+
slot_length_mins: 60,
|
27
|
+
interval_mins: 15,
|
29
28
|
exclude_times: [
|
30
|
-
|
29
|
+
Time.new(2020, 05, 01, 9, 00)..Time.new(2020, 05, 01, 10, 00)
|
31
30
|
]
|
32
31
|
)
|
33
32
|
|
@@ -45,6 +44,8 @@ Slotty.get_slots(
|
|
45
44
|
# ]
|
46
45
|
```
|
47
46
|
|
47
|
+
If you want to just receive the human times back (i.e. "10:00 AM"), you can pass `for: :to_s` to `#get_slots`
|
48
|
+
|
48
49
|
## Development
|
49
50
|
|
50
51
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/slotty.rb
CHANGED
@@ -1,29 +1,40 @@
|
|
1
1
|
require "slotty/version"
|
2
|
-
require "slotty/
|
2
|
+
require "slotty/timeframe"
|
3
|
+
require "slotty/slot"
|
3
4
|
|
4
5
|
module Slotty
|
5
|
-
|
6
|
+
InvalidFormatError = Class.new(StandardError)
|
7
|
+
InvalidDateError = Class.new(StandardError)
|
8
|
+
InvalidSlotLengthError = Class.new(StandardError)
|
9
|
+
InvalidIntervalError = Class.new(StandardError)
|
10
|
+
InvalidExclusionError = Class.new(StandardError)
|
6
11
|
|
7
12
|
class << self
|
8
|
-
def get_slots(
|
13
|
+
def get_slots(for_range:, slot_length_mins:, interval_mins:, as: :full, exclude_times: [])
|
14
|
+
raise InvalidDateError, "for_value must be type of Range" unless for_range.is_a?(Range)
|
15
|
+
raise InvalidSlotLengthError, "slot_length_mins must be an integer" unless slot_length_mins.is_a?(Integer)
|
16
|
+
raise InvalidIntervalError, "interval_mins must be an integer" unless interval_mins.is_a?(Integer)
|
17
|
+
raise InvalidExclusionError, "exclude_times must be an array of time ranges" unless exclude_times.is_a?(Array) && exclude_times.all? { |t| t.is_a?(Range) }
|
18
|
+
|
19
|
+
slot_length = slot_length_mins * 60
|
20
|
+
interval = interval_mins * 60
|
21
|
+
|
9
22
|
slots = Array.new(0)
|
10
23
|
|
11
|
-
potential_slot =
|
24
|
+
potential_slot = Slot.new(range: for_range.begin..(for_range.begin + slot_length))
|
12
25
|
|
13
|
-
while
|
14
|
-
if
|
15
|
-
potential_slot = (potential_slot.begin +
|
26
|
+
while Timeframe.covers?(for_range, potential_slot)
|
27
|
+
if potential_slot.has_overlaps?(exclude_times)
|
28
|
+
potential_slot = Slot.new(range: (potential_slot.begin + interval)..(potential_slot.begin + interval + slot_length))
|
16
29
|
|
17
30
|
next
|
18
31
|
end
|
19
32
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
time: potential_slot.begin.strftime('%H:%M %p')
|
24
|
-
}
|
33
|
+
raise InvalidFormatError, "cannot format slot in this way" unless potential_slot.respond_to?(as)
|
34
|
+
|
35
|
+
slots << potential_slot.send(as)
|
25
36
|
|
26
|
-
potential_slot = (potential_slot.begin +
|
37
|
+
potential_slot = Slot.new(range: (potential_slot.begin + interval)..(potential_slot.begin + interval + slot_length))
|
27
38
|
end
|
28
39
|
|
29
40
|
slots
|
data/lib/slotty/slot.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require "slotty/timeframe"
|
2
|
+
|
3
|
+
module Slotty
|
4
|
+
class Slot
|
5
|
+
attr_reader :range, :begin, :end
|
6
|
+
|
7
|
+
def initialize(range:)
|
8
|
+
@range = range
|
9
|
+
@begin = range.begin
|
10
|
+
@end = range.end
|
11
|
+
end
|
12
|
+
|
13
|
+
def has_overlaps?(excluded_slots = [])
|
14
|
+
return false if excluded_slots.empty?
|
15
|
+
|
16
|
+
excluded_slots.any? do |exc_slot|
|
17
|
+
Timeframe.contains?(exc_slot, range)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
range.begin.strftime('%I:%M %p')
|
23
|
+
end
|
24
|
+
|
25
|
+
def full
|
26
|
+
{
|
27
|
+
start_time: range.begin,
|
28
|
+
end_time: range.end,
|
29
|
+
time: to_s
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Slotty
|
2
|
+
class Timeframe
|
3
|
+
class << self
|
4
|
+
def covers?(surrounding_range, included_range)
|
5
|
+
starts_before = surrounding_range.begin <= included_range.begin
|
6
|
+
ends_after = surrounding_range.end >= included_range.end
|
7
|
+
|
8
|
+
starts_before && ends_after
|
9
|
+
end
|
10
|
+
|
11
|
+
def contains?(excluder, potential_slot)
|
12
|
+
start_within = potential_slot.begin >= excluder.begin && potential_slot.begin < excluder.end
|
13
|
+
end_within = potential_slot.end > excluder.begin && potential_slot.end <= excluder.end
|
14
|
+
|
15
|
+
start_within || end_within
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
data/lib/slotty/version.rb
CHANGED
data/slotty-0.1.0.gem
ADDED
Binary file
|
data/slotty.gemspec
CHANGED
@@ -24,6 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
-
spec.add_development_dependency "rake", "~>
|
27
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slotty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hayden Rouille
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 12.3.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 12.3.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- ".rspec"
|
65
|
+
- ".tool-versions"
|
65
66
|
- ".travis.yml"
|
66
67
|
- CODE_OF_CONDUCT.md
|
67
68
|
- Gemfile
|
@@ -72,8 +73,10 @@ files:
|
|
72
73
|
- bin/console
|
73
74
|
- bin/setup
|
74
75
|
- lib/slotty.rb
|
75
|
-
- lib/slotty/
|
76
|
+
- lib/slotty/slot.rb
|
77
|
+
- lib/slotty/timeframe.rb
|
76
78
|
- lib/slotty/version.rb
|
79
|
+
- slotty-0.1.0.gem
|
77
80
|
- slotty.gemspec
|
78
81
|
homepage: https://github.com/haydenrou/slotty
|
79
82
|
licenses:
|
@@ -94,7 +97,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
97
|
- !ruby/object:Gem::Version
|
95
98
|
version: '0'
|
96
99
|
requirements: []
|
97
|
-
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.7.3
|
98
102
|
signing_key:
|
99
103
|
specification_version: 4
|
100
104
|
summary: Generate available slots between time ranges
|
data/lib/slotty/validator.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
module Slotty
|
2
|
-
class Validator
|
3
|
-
class << self
|
4
|
-
def has_overlaps?(slot, excluded_slots = [])
|
5
|
-
return false if excluded_slots.empty?
|
6
|
-
|
7
|
-
excluded_slots.any? do |excluder|
|
8
|
-
excluder_overlaps_slot_start = (excluder[:start]..excluder[:end]).include? slot.begin
|
9
|
-
excluder_overlaps_slot_end = (excluder[:start]..excluder[:end]).include? slot.end
|
10
|
-
slot_overlaps_excluder_start = (slot.begin..slot.end).include? excluder[:start]
|
11
|
-
slot_overlaps_excluder_end = (slot.begin..slot.end).include? excluder[:end]
|
12
|
-
|
13
|
-
excluder_overlaps_slot_start |
|
14
|
-
excluder_overlaps_slot_end |
|
15
|
-
slot_overlaps_excluder_start |
|
16
|
-
slot_overlaps_excluder_end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|