fat_core 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fat_core/range.rb +4 -1
- data/lib/fat_core/version.rb +1 -1
- data/spec/lib/period_spec.rb +19 -0
- data/spec/lib/range_spec.rb +8 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54ce983c1d43b7c9b67972299a634117b7d7de2d
|
4
|
+
data.tar.gz: 41b1588e17acfc8e918726d6ff358df23d8c3076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f34ec86d849b6e8f1d3484238ac57a56142d4a9b4744048109dd515a0d38d8231c727d81951e41045c1333c04eb2d5c5b1d71badff7331a93a9f3977855c247
|
7
|
+
data.tar.gz: 108f60886a9b08b084a58ab8152d9a1cb1a4f0c647abffbfc614eee904c9b7892846be940faaec9c8f1afe4848263752cdc516996900180f76bc2b522cbeb2fc
|
data/lib/fat_core/range.rb
CHANGED
@@ -145,12 +145,15 @@ class Range
|
|
145
145
|
gaps = []
|
146
146
|
cur_point = min
|
147
147
|
ranges.each do |rr|
|
148
|
+
break if rr.min > max
|
148
149
|
if rr.min > cur_point
|
149
150
|
start_point = cur_point
|
150
151
|
end_point = rr.min.pred
|
151
152
|
gaps << (start_point..end_point)
|
153
|
+
cur_point = rr.max.succ
|
154
|
+
elsif rr.max > cur_point
|
155
|
+
cur_point = rr.max.succ
|
152
156
|
end
|
153
|
-
cur_point = rr.max.succ
|
154
157
|
end
|
155
158
|
if cur_point < max
|
156
159
|
gaps << (cur_point..max)
|
data/lib/fat_core/version.rb
CHANGED
data/spec/lib/period_spec.rb
CHANGED
@@ -342,5 +342,24 @@ describe Period do
|
|
342
342
|
month = Period.parse_spec('this_month')
|
343
343
|
expect(last_year - month).to eq([last_year])
|
344
344
|
end
|
345
|
+
|
346
|
+
it "should be able to find gaps from an array of periods" do
|
347
|
+
pp = Period.parse_spec('2014-2Q')
|
348
|
+
periods = [
|
349
|
+
Period.parse_spec('2013-11', '2013-12-20'),
|
350
|
+
Period.parse_spec('2014-01', '2014-04-20'),
|
351
|
+
# Gap 2014-04-21 to 2014-04-30
|
352
|
+
Period.parse_spec('2014-05', '2014-05-11'),
|
353
|
+
# Gap 2014-05-12 to 2014-05-24
|
354
|
+
Period.parse_spec('2014-05-25', '2014-07-11'),
|
355
|
+
Period.parse_spec('2014-09')
|
356
|
+
]
|
357
|
+
gaps = pp.gaps(periods)
|
358
|
+
expect(gaps.size).to eq(2)
|
359
|
+
expect(gaps.first.first).to eq(Date.parse('2014-04-21'))
|
360
|
+
expect(gaps.first.last).to eq(Date.parse('2014-04-30'))
|
361
|
+
expect(gaps.last.first).to eq(Date.parse('2014-05-12'))
|
362
|
+
expect(gaps.last.last).to eq(Date.parse('2014-05-24'))
|
363
|
+
end
|
345
364
|
end
|
346
365
|
end
|
data/spec/lib/range_spec.rb
CHANGED
@@ -204,14 +204,20 @@ describe Range do
|
|
204
204
|
expect(gaps).to be_empty
|
205
205
|
end
|
206
206
|
|
207
|
-
it "should
|
207
|
+
it "should not include parts before or after in gaps" do
|
208
|
+
gaps = (0..10).gaps([(-10..-8), (-3..3), (7..13), (30..40)])
|
209
|
+
expect(gaps.size).to eq(1)
|
210
|
+
expect(gaps[0]).to eq((4..6))
|
211
|
+
end
|
212
|
+
|
213
|
+
it "should return gaps at beginning and end" do
|
208
214
|
gaps = (0..10).gaps([(2..3), (4..6), (7..8)])
|
209
215
|
expect(gaps[0]).to eq((0..1))
|
210
216
|
expect(gaps[1]).to eq((9..10))
|
211
217
|
end
|
212
218
|
|
213
219
|
it "should work even if ranges are out of order" do
|
214
|
-
gaps = (0..10).gaps([(2..3), (7..8), (4..6)])
|
220
|
+
gaps = (0..10).gaps([(2..3), (30..40), (7..8), (-10..-8), (4..6)])
|
215
221
|
expect(gaps[0]).to eq((0..1))
|
216
222
|
expect(gaps[1]).to eq((9..10))
|
217
223
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fat_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-10-
|
11
|
+
date: 2014-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|