slot_machine 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.rdoc +8 -0
- data/Gemfile +2 -13
- data/MIT-LICENSE +1 -1
- data/README.md +2 -2
- data/VERSION +1 -1
- data/lib/slot_machine.rb +7 -2
- data/lib/slot_machine/slot.rb +19 -1
- data/lib/slot_machine/slots.rb +130 -0
- data/lib/slot_machine/version.rb +1 -1
- data/lib/slots.rb +3 -0
- data/lib/time_slot.rb +4 -0
- data/lib/time_slots.rb +3 -0
- data/script/console +1 -4
- data/slot_machine.gemspec +5 -1
- data/test/test_helper.rb +3 -4
- data/test/unit/test_slot.rb +24 -2
- data/test/unit/test_slots.rb +117 -0
- data/test/unit/test_time_slot.rb +20 -0
- data/test/unit/test_time_slots.rb +54 -0
- metadata +62 -45
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b1284fee79db641ca71f72ab2e27cb60ddcaa746
|
4
|
+
data.tar.gz: 31bde868b4da37d7212774fcf38fffb8c8a8c2a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 59638a38e444e119286deff086c8b946e8c8f33af5858995bba77c0837faa3aebaab4b74a58f30a74072d1a774f182e8077c7737ebf6de475d7d469f7052c69c
|
7
|
+
data.tar.gz: d149fba61a6c0edde6952ddb408bdd275a59738deb31925fe8eaad74cce2a9bf3bc897d4670a55d2b53076f11288cbeed03d95904f5a14ac3e67fa8e92a5b347
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= SlotMachine CHANGELOG
|
2
2
|
|
3
|
+
== Version 0.1.1 (July 10, 2013)
|
4
|
+
|
5
|
+
* Introduced SlotMachine::Slots (also Slots and TimeSlots) for addition and subtraction of slots
|
6
|
+
* Being able to match available slots within slots
|
7
|
+
* Merging ranges on initialization of a slots instance
|
8
|
+
* Accepting Time objects within TimeSlot
|
9
|
+
* Improved Bundler setup
|
10
|
+
|
3
11
|
== Version 0.1.0 (September 16, 2012)
|
4
12
|
|
5
13
|
* Initial release
|
data/Gemfile
CHANGED
@@ -1,18 +1,7 @@
|
|
1
|
-
source "
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
group :
|
6
|
-
gem "slot_machine", :path => "."
|
7
|
-
end
|
8
|
-
|
9
|
-
group :gem_development do
|
10
|
-
gem "pry"
|
11
|
-
end
|
12
|
-
|
13
|
-
group :gem_test do
|
14
|
-
gem "minitest"
|
15
|
-
gem "mocha"
|
5
|
+
group :console do
|
16
6
|
gem "pry"
|
17
|
-
gem "rake"
|
18
7
|
end
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -127,7 +127,7 @@ Well that's about it! Pretty straightforward, right? Have fun playing with the `
|
|
127
127
|
|
128
128
|
## TODO
|
129
129
|
|
130
|
-
*
|
130
|
+
* Update documentation regarding Slots, TimeSlots and Time objects
|
131
131
|
|
132
132
|
## Contact me
|
133
133
|
|
@@ -135,7 +135,7 @@ For support, remarks and requests, please mail me at [paul.engel@holder.nl](mail
|
|
135
135
|
|
136
136
|
## License
|
137
137
|
|
138
|
-
Copyright (c)
|
138
|
+
Copyright (c) 2013 Paul Engel, released under the MIT license
|
139
139
|
|
140
140
|
[http://holder.nl](http://holder.nl) - [http://codehero.es](http://codehero.es) - [http://gettopup.com](http://gettopup.com) - [http://github.com/archan937](http://github.com/archan937) - [http://twitter.com/archan937](http://twitter.com/archan937) - [paul.engel@holder.nl](mailto:paul.engel@holder.nl)
|
141
141
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/lib/slot_machine.rb
CHANGED
data/lib/slot_machine/slot.rb
CHANGED
@@ -12,6 +12,12 @@ module SlotMachine
|
|
12
12
|
def self.default_interval
|
13
13
|
@interval || 10
|
14
14
|
end
|
15
|
+
|
16
|
+
def self.slots_class
|
17
|
+
@slots_class ||= "#{name}s".split("::").inject(Object) do |mod, name|
|
18
|
+
mod.const_get name
|
19
|
+
end
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
|
@@ -55,6 +61,14 @@ module SlotMachine
|
|
55
61
|
match_compared to_compared, other.to_compared, interval
|
56
62
|
end
|
57
63
|
|
64
|
+
def +(other)
|
65
|
+
self.class.slots_class.new(self) + other
|
66
|
+
end
|
67
|
+
|
68
|
+
def -(other)
|
69
|
+
self.class.slots_class.new(self) - other
|
70
|
+
end
|
71
|
+
|
58
72
|
def ==(other)
|
59
73
|
self.class == other.class && self.start == other.start && self.end == other.end && self.length == other.length
|
60
74
|
end
|
@@ -72,6 +86,10 @@ module SlotMachine
|
|
72
86
|
|
73
87
|
protected
|
74
88
|
|
89
|
+
def typecast(value)
|
90
|
+
value.to_s
|
91
|
+
end
|
92
|
+
|
75
93
|
def valid?(value)
|
76
94
|
true
|
77
95
|
end
|
@@ -125,7 +143,7 @@ module SlotMachine
|
|
125
143
|
end
|
126
144
|
|
127
145
|
def typecast!(value, operator, compared)
|
128
|
-
Integer(value
|
146
|
+
Integer(typecast(value)).tap do |value|
|
129
147
|
raise ArgumentError, "Passed value should be #{operator} #{compared} (#{value} given)" if compared && !value.send(operator, compared)
|
130
148
|
end
|
131
149
|
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
module SlotMachine
|
2
|
+
module Slots
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.class_eval do
|
6
|
+
def self.slot_class
|
7
|
+
@slot_class ||= name.gsub(/s$/, "").split("::").inject(Object) do |mod, name|
|
8
|
+
mod.const_get name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(*ranges_or_range_slots)
|
15
|
+
@range_slots = to_range_slots(add(ranges_or_range_slots.flatten))
|
16
|
+
end
|
17
|
+
|
18
|
+
def range_slots
|
19
|
+
@range_slots || []
|
20
|
+
end
|
21
|
+
|
22
|
+
def match(other, interval = nil)
|
23
|
+
range_slots.collect{|range_slot| range_slot.match other, interval}.flatten.uniq
|
24
|
+
end
|
25
|
+
|
26
|
+
def +(other)
|
27
|
+
unless other.is_a?(Range) || other.is_a?(Array) || other.class == self.class.slot_class || other.class == self.class
|
28
|
+
raise ArgumentError, "Either subtract a Range, an Array, #{self.class.slot_class.name} or #{self.class.name} instance (#{other.class.name} given)"
|
29
|
+
end
|
30
|
+
self.class.new add(other)
|
31
|
+
end
|
32
|
+
|
33
|
+
def -(other)
|
34
|
+
unless other.is_a?(Range) || other.is_a?(Array) || other.class == self.class.slot_class || other.class == self.class
|
35
|
+
raise ArgumentError, "Either subtract a Range, an Array, #{self.class.slot_class.name} or #{self.class.name} instance (#{other.class.name} given)"
|
36
|
+
end
|
37
|
+
self.class.new subtract(other)
|
38
|
+
end
|
39
|
+
|
40
|
+
def ==(other)
|
41
|
+
((self.class == other.class) || (other_is_an_array = other.is_a?(Array))) && begin
|
42
|
+
range_slots.size == (other_range_slots = other_is_an_array ? other : other.range_slots).size && begin
|
43
|
+
range_slots.each_with_index do |range_slot, index|
|
44
|
+
return false unless range_slot == other_range_slots[index]
|
45
|
+
end
|
46
|
+
true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def to_range_slots(ranges_or_range_slots)
|
54
|
+
ranges_or_range_slots.flatten.collect do |range_or_range_slot|
|
55
|
+
if range_or_range_slot.class == self.class.slot_class
|
56
|
+
range_or_range_slot
|
57
|
+
elsif range_or_range_slot.is_a?(Range)
|
58
|
+
self.class.slot_class.new range_or_range_slot
|
59
|
+
else
|
60
|
+
raise ArgumentError
|
61
|
+
end
|
62
|
+
end.sort do |a, b|
|
63
|
+
[a.start, a.end] <=> [b.start, b.end]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_ranges(object)
|
68
|
+
begin
|
69
|
+
if object.is_a?(Range) || object.class == self.class.slot_class
|
70
|
+
[object]
|
71
|
+
elsif object.class == self.class
|
72
|
+
object.range_slots
|
73
|
+
else
|
74
|
+
object
|
75
|
+
end
|
76
|
+
end.collect do |entry|
|
77
|
+
if entry.class == self.class.slot_class
|
78
|
+
entry.start..entry.end
|
79
|
+
elsif entry.is_a?(Range)
|
80
|
+
entry
|
81
|
+
else
|
82
|
+
raise ArgumentError
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def add(other)
|
88
|
+
*merged_ranges = (ranges = to_ranges(self).concat(to_ranges(other)).sort{|a, b| [a.first, a.last] <=> [b.first, b.last]}).shift
|
89
|
+
ranges.each do |range|
|
90
|
+
last_range = merged_ranges[-1]
|
91
|
+
if last_range.last >= range.first - 1
|
92
|
+
merged_ranges[-1] = last_range.first..[range.last, last_range.last].max
|
93
|
+
else
|
94
|
+
merged_ranges.push range
|
95
|
+
end
|
96
|
+
end
|
97
|
+
merged_ranges
|
98
|
+
end
|
99
|
+
|
100
|
+
def subtract(other)
|
101
|
+
divided_ranges = to_ranges(self)
|
102
|
+
to_ranges(other).each do |range|
|
103
|
+
divided_ranges = divided_ranges.collect do |divided_range|
|
104
|
+
if range.first <= divided_range.first && range.last > divided_range.first && range.last < divided_range.last
|
105
|
+
# | range |
|
106
|
+
# | divided_range |
|
107
|
+
range.last..divided_range.last
|
108
|
+
elsif range.first > divided_range.first && range.first < divided_range.last && range.last >= divided_range.last
|
109
|
+
# | range |
|
110
|
+
# | divided_range |
|
111
|
+
divided_range.first..range.first
|
112
|
+
elsif range.first > divided_range.first && range.last < divided_range.last
|
113
|
+
# | range |
|
114
|
+
# | divided_range |
|
115
|
+
[divided_range.first..range.first, range.last..divided_range.last]
|
116
|
+
elsif range.last <= divided_range.first || range.first >= divided_range.last
|
117
|
+
# | range |
|
118
|
+
# | divided_range |
|
119
|
+
# or
|
120
|
+
# | range |
|
121
|
+
# | divided_range |
|
122
|
+
divided_range
|
123
|
+
end
|
124
|
+
end.flatten.compact
|
125
|
+
end
|
126
|
+
divided_ranges
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
data/lib/slot_machine/version.rb
CHANGED
data/lib/slots.rb
ADDED
data/lib/time_slot.rb
CHANGED
data/lib/time_slots.rb
ADDED
data/script/console
CHANGED
data/slot_machine.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/slot_machine/version", __FILE__)
|
2
3
|
|
3
4
|
Gem::Specification.new do |gem|
|
4
5
|
gem.authors = ["Paul Engel"]
|
@@ -12,5 +13,8 @@ Gem::Specification.new do |gem|
|
|
12
13
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
13
14
|
gem.name = "slot_machine"
|
14
15
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version =
|
16
|
+
gem.version = SlotMachine::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency "minitest", "4.6.2"
|
19
|
+
gem.add_development_dependency "mocha", "0.13.2"
|
16
20
|
end
|
data/test/test_helper.rb
CHANGED
data/test/unit/test_slot.rb
CHANGED
@@ -14,6 +14,11 @@ module Unit
|
|
14
14
|
interval 20
|
15
15
|
end
|
16
16
|
assert_equal 20, Slot.default_interval
|
17
|
+
|
18
|
+
Slot.class_eval do
|
19
|
+
interval 10
|
20
|
+
end
|
21
|
+
assert_equal 10, Slot.default_interval
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|
@@ -28,8 +33,10 @@ module Unit
|
|
28
33
|
assert slot.respond_to?(:end=)
|
29
34
|
assert slot.respond_to?(:length)
|
30
35
|
assert slot.respond_to?(:length=)
|
31
|
-
assert slot.respond_to?(:to_compared)
|
36
|
+
assert slot.respond_to?(:to_compared, true)
|
32
37
|
assert slot.respond_to?(:match)
|
38
|
+
assert slot.respond_to?(:+)
|
39
|
+
assert slot.respond_to?(:-)
|
33
40
|
end
|
34
41
|
end
|
35
42
|
|
@@ -75,7 +82,7 @@ module Unit
|
|
75
82
|
end
|
76
83
|
|
77
84
|
describe "equality" do
|
78
|
-
it "should return whether it equals another
|
85
|
+
it "should return whether it equals another object" do
|
79
86
|
slot = Slot.new 1
|
80
87
|
|
81
88
|
assert !(slot == 1)
|
@@ -190,6 +197,20 @@ module Unit
|
|
190
197
|
Slot.new(5).match(5)
|
191
198
|
end
|
192
199
|
end
|
200
|
+
|
201
|
+
it "should be able to add other slots" do
|
202
|
+
assert_equal Slots, (Slot.new(1..10) + (5..8)).class
|
203
|
+
assert_equal Slots, (Slot.new(1..10) + Slot.new(5..8)).class
|
204
|
+
assert_equal Slots, (Slot.new(1..10) + [5..8]).class
|
205
|
+
assert_equal Slots, (Slot.new(1..10) + Slots.new([5..8])).class
|
206
|
+
end
|
207
|
+
|
208
|
+
it "should be able to subtract other slots" do
|
209
|
+
assert_equal Slots, (Slot.new(1..10) - (5..8)).class
|
210
|
+
assert_equal Slots, (Slot.new(1..10) - Slot.new(5..8)).class
|
211
|
+
assert_equal Slots, (Slot.new(1..10) - [5..8]).class
|
212
|
+
assert_equal Slots, (Slot.new(1..10) - Slots.new([5..8])).class
|
213
|
+
end
|
193
214
|
end
|
194
215
|
|
195
216
|
describe "length slots" do
|
@@ -233,5 +254,6 @@ module Unit
|
|
233
254
|
end
|
234
255
|
end
|
235
256
|
end
|
257
|
+
|
236
258
|
end
|
237
259
|
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
class TestSlots < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
describe Slots do
|
7
|
+
describe "instance methods" do
|
8
|
+
it "should have the expected instance methods" do
|
9
|
+
slots = Slots.new 1..10
|
10
|
+
assert slots.respond_to?(:range_slots)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "initialization" do
|
15
|
+
it "should accept a range" do
|
16
|
+
slots = Slots.new 10..20
|
17
|
+
assert_equal [Slot.new(10..20)], slots.range_slots
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should accept ranges" do
|
21
|
+
slots = Slots.new 10..20, Slot.new(30..40)
|
22
|
+
assert_equal [Slot.new(10..20), Slot.new(30..40)], slots.range_slots
|
23
|
+
|
24
|
+
slots = Slots.new 10..20, Slot.new(22..30)
|
25
|
+
assert_equal [Slot.new(10..20), Slot.new(22..30)], slots.range_slots
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should merge slots on initialization" do
|
29
|
+
slots = Slots.new 10..20, 20..30
|
30
|
+
assert_equal [Slot.new(10..30)], slots.range_slots
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should raise an exception when invalid" do
|
34
|
+
assert_raises ArgumentError do
|
35
|
+
Slots.new "bar"
|
36
|
+
end
|
37
|
+
assert_raises ArgumentError do
|
38
|
+
Slots.new 1.."bar"
|
39
|
+
end
|
40
|
+
assert_raises ArgumentError do
|
41
|
+
Slots.new "bar"..1
|
42
|
+
end
|
43
|
+
assert_raises ArgumentError do
|
44
|
+
Slots.new "slot".."bar"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "equality" do
|
50
|
+
it "should return whether it equals another object" do
|
51
|
+
slots = Slots.new 1..2, 3..4
|
52
|
+
|
53
|
+
assert !(slots == Slot.new(1..2))
|
54
|
+
assert !(slots == Slots.new(1..2, 3..5))
|
55
|
+
|
56
|
+
assert_equal slots, Slots.new(3..4, 1..2)
|
57
|
+
assert_equal slots, Slots.new(1..2, 3..4)
|
58
|
+
assert_equal slots, Slots.new([1..2, 3..4])
|
59
|
+
assert_equal slots, Slots.new(Slot.new(1..2), Slot.new(3..4))
|
60
|
+
assert_equal slots, [Slot.new(1..4)]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "calculations" do
|
65
|
+
it "should be able to add slots" do
|
66
|
+
slots = Slots.new 0..10
|
67
|
+
|
68
|
+
assert_equal Slots, (slots + (10..20)).class
|
69
|
+
assert_equal Slots, (slots + Slot.new(10..20)).class
|
70
|
+
assert_equal Slots, (slots + Slots.new(10..20)).class
|
71
|
+
|
72
|
+
assert_equal Slots.new(0..20), (slots + (10..20))
|
73
|
+
assert_equal Slots.new(0..10, 20..30), (slots + Slot.new(20..30))
|
74
|
+
assert_equal Slots.new(0..10, 20..30, 40..60), (slots + Slots.new(20..30, 40..50) + (45..60))
|
75
|
+
|
76
|
+
assert_equal Slots.new(0..15, 20..30), (((slots + (5..15)) + (20..25)) + (24..30))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be able to subtract slots" do
|
80
|
+
slots = Slots.new 0..30
|
81
|
+
|
82
|
+
assert_equal Slots, (slots - (10..20)).class
|
83
|
+
assert_equal Slots, (slots - Slot.new(10..20)).class
|
84
|
+
assert_equal Slots, (slots - Slots.new(10..20)).class
|
85
|
+
|
86
|
+
assert_equal Slots.new(0..10, 20..30), (slots - (10..20))
|
87
|
+
assert_equal Slots.new(0..10, 20..30), (slots - Slot.new(10..20))
|
88
|
+
assert_equal Slots.new(0..10, 20..30), (slots - Slots.new(10..20, 30..40))
|
89
|
+
|
90
|
+
assert_equal Slots.new(0..5, 10..20, 25..30), (((slots - (20..25)) - (5..10)) - (20..22))
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should be able to match available slots" do
|
94
|
+
slots = Slots.new(0..10, 15..40, 50..65)
|
95
|
+
|
96
|
+
assert_equal [
|
97
|
+
Slot.new(0..10),
|
98
|
+
Slot.new(15..25),
|
99
|
+
Slot.new(25..35),
|
100
|
+
Slot.new(50..60)
|
101
|
+
], slots.match(10)
|
102
|
+
|
103
|
+
assert_equal [
|
104
|
+
Slot.new(0..10),
|
105
|
+
Slot.new(15..25),
|
106
|
+
Slot.new(20..30),
|
107
|
+
Slot.new(25..35),
|
108
|
+
Slot.new(30..40),
|
109
|
+
Slot.new(50..60),
|
110
|
+
Slot.new(55..65)
|
111
|
+
], slots.match(10, 5)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
data/test/unit/test_time_slot.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require File.expand_path("../../test_helper", __FILE__)
|
2
2
|
|
3
|
+
require "time"
|
4
|
+
|
3
5
|
module Unit
|
4
6
|
class TestTimeSlot < MiniTest::Unit::TestCase
|
5
7
|
|
@@ -15,6 +17,17 @@ module Unit
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
20
|
+
it "should accept time objects" do
|
21
|
+
assert_equal [
|
22
|
+
198208010859,
|
23
|
+
198208010900,
|
24
|
+
198208010901,
|
25
|
+
198208010902,
|
26
|
+
198208010903,
|
27
|
+
198208010904
|
28
|
+
], TimeSlot.new(Time.parse("1982-08-01 08:59")..Time.parse("1982-08-01 09:05")).send(:to_compared)
|
29
|
+
end
|
30
|
+
|
18
31
|
it "should represent itself as an array when invoking to_compared" do
|
19
32
|
assert_equal 10 , TimeSlot.new(855..905).send(:to_compared).size
|
20
33
|
assert_equal 222, TimeSlot.new(955..1337).send(:to_compared).size
|
@@ -42,6 +55,13 @@ module Unit
|
|
42
55
|
TimeSlot.new(1109..1149)
|
43
56
|
], time_slot.match(40, 18)
|
44
57
|
|
58
|
+
assert_equal [
|
59
|
+
TimeSlot.new(198208011015..198208011055),
|
60
|
+
TimeSlot.new(198208011033..198208011113),
|
61
|
+
TimeSlot.new(198208011051..198208011131),
|
62
|
+
TimeSlot.new(198208011109..198208011149)
|
63
|
+
], TimeSlot.new(Time.parse("1982-08-01 10:15")..Time.parse("1982-08-01 12:00")).match(40, 18)
|
64
|
+
|
45
65
|
assert_equal [], time_slot.match(945..1005)
|
46
66
|
assert_equal [], time_slot.match(1205..1225)
|
47
67
|
assert_equal [TimeSlot.new(1015..1200)], time_slot.match(1015..1200)
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path("../../test_helper", __FILE__)
|
2
|
+
|
3
|
+
module Unit
|
4
|
+
class TestTimeSlots < MiniTest::Unit::TestCase
|
5
|
+
|
6
|
+
describe TimeSlots do
|
7
|
+
it "should merge slots on initialization" do
|
8
|
+
time_slots = TimeSlots.new 1015..1100, 1100..1115
|
9
|
+
assert_equal [TimeSlot.new(1015..1115)], time_slots.range_slots
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to add slots" do
|
13
|
+
time_slot = TimeSlot.new 1015..1100
|
14
|
+
|
15
|
+
assert_equal TimeSlots.new(1015..1130), (time_slot + (1055..1130))
|
16
|
+
assert_equal TimeSlots.new(1015..1130), (time_slot + TimeSlot.new(1055..1130))
|
17
|
+
assert_equal TimeSlots.new(1015..1130, 1145..1200), (time_slot + TimeSlots.new(1055..1130, 1145..1200))
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be able to subtract slots" do
|
21
|
+
time_slot = TimeSlot.new 1015..1100
|
22
|
+
|
23
|
+
assert_equal TimeSlots.new(1015..1030, 1045..1100), (time_slot - (1030..1045))
|
24
|
+
assert_equal TimeSlots.new(1015..1055), (time_slot - TimeSlot.new(1055..1130))
|
25
|
+
assert_equal TimeSlots.new(1015..1045, 1055..1100), (time_slot - TimeSlots.new(1045..1055, 1145..1200))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be able to match available slots" do
|
29
|
+
time_slots = TimeSlots.new(1015..1100, 1230..1337)
|
30
|
+
|
31
|
+
assert_equal [
|
32
|
+
TimeSlot.new(1015..1035),
|
33
|
+
TimeSlot.new(1030..1050),
|
34
|
+
TimeSlot.new(1230..1250),
|
35
|
+
TimeSlot.new(1245..1305),
|
36
|
+
TimeSlot.new(1300..1320),
|
37
|
+
TimeSlot.new(1315..1335)
|
38
|
+
], time_slots.match(20)
|
39
|
+
|
40
|
+
assert_equal [
|
41
|
+
TimeSlot.new(1015..1035),
|
42
|
+
TimeSlot.new(1025..1045),
|
43
|
+
TimeSlot.new(1035..1055),
|
44
|
+
TimeSlot.new(1230..1250),
|
45
|
+
TimeSlot.new(1240..1300),
|
46
|
+
TimeSlot.new(1250..1310),
|
47
|
+
TimeSlot.new(1300..1320),
|
48
|
+
TimeSlot.new(1310..1330)
|
49
|
+
], time_slots.match(20, 10)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,33 +1,53 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: slot_machine
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 1
|
9
|
-
- 0
|
10
|
-
version: 0.1.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Paul Engel
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
date: 2013-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.6.2
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.6.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mocha
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.13.2
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.13.2
|
41
|
+
description: One of the classic programming problems is the determination of time
|
42
|
+
slot availability. Very often this is used within scheduling / calendar programs.
|
43
|
+
SlotMachine is a very small Ruby gem which can do the job for you. It does not only
|
44
|
+
focuses on time slots, but also slots in general.
|
45
|
+
email:
|
23
46
|
- paul.engel@holder.nl
|
24
47
|
executables: []
|
25
|
-
|
26
48
|
extensions: []
|
27
|
-
|
28
49
|
extra_rdoc_files: []
|
29
|
-
|
30
|
-
files:
|
50
|
+
files:
|
31
51
|
- .gitignore
|
32
52
|
- .travis.yml
|
33
53
|
- CHANGELOG.rdoc
|
@@ -39,47 +59,44 @@ files:
|
|
39
59
|
- lib/slot.rb
|
40
60
|
- lib/slot_machine.rb
|
41
61
|
- lib/slot_machine/slot.rb
|
62
|
+
- lib/slot_machine/slots.rb
|
42
63
|
- lib/slot_machine/version.rb
|
64
|
+
- lib/slots.rb
|
43
65
|
- lib/time_slot.rb
|
66
|
+
- lib/time_slots.rb
|
44
67
|
- script/console
|
45
68
|
- slot_machine.gemspec
|
46
69
|
- test/test_helper.rb
|
47
70
|
- test/unit/test_slot.rb
|
71
|
+
- test/unit/test_slots.rb
|
48
72
|
- test/unit/test_time_slot.rb
|
73
|
+
- test/unit/test_time_slots.rb
|
49
74
|
homepage: https://github.com/archan937/slot_machine
|
50
75
|
licenses: []
|
51
|
-
|
76
|
+
metadata: {}
|
52
77
|
post_install_message:
|
53
78
|
rdoc_options: []
|
54
|
-
|
55
|
-
require_paths:
|
79
|
+
require_paths:
|
56
80
|
- lib
|
57
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
none: false
|
68
|
-
requirements:
|
69
|
-
- - ">="
|
70
|
-
- !ruby/object:Gem::Version
|
71
|
-
hash: 3
|
72
|
-
segments:
|
73
|
-
- 0
|
74
|
-
version: "0"
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
75
91
|
requirements: []
|
76
|
-
|
77
92
|
rubyforge_project:
|
78
|
-
rubygems_version:
|
93
|
+
rubygems_version: 2.0.3
|
79
94
|
signing_key:
|
80
|
-
specification_version:
|
95
|
+
specification_version: 4
|
81
96
|
summary: Ruby gem for matching available slots (time slots are also supported)
|
82
|
-
test_files:
|
97
|
+
test_files:
|
83
98
|
- test/test_helper.rb
|
84
99
|
- test/unit/test_slot.rb
|
100
|
+
- test/unit/test_slots.rb
|
85
101
|
- test/unit/test_time_slot.rb
|
102
|
+
- test/unit/test_time_slots.rb
|