fat_core 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fec1975ce07c2b6e810e15af087c374d24bae021
4
- data.tar.gz: 2f9de5ecd6a2ccc1b02712d7be0842663a324f06
3
+ metadata.gz: 54ce983c1d43b7c9b67972299a634117b7d7de2d
4
+ data.tar.gz: 41b1588e17acfc8e918726d6ff358df23d8c3076
5
5
  SHA512:
6
- metadata.gz: 741aa2222e9b8318279a22c7484b6a2d31e610c4c00bbab2ec7ad888d838068dac6861c00f4baf0a0866903d5647268fd49a73ccf1ecb5a93c71a9879362443d
7
- data.tar.gz: 0fdea514902090b8b8b4dd0d0325121ac8bd33e6b1af0467e978e37d8eae913b2f35c24ad6518015602a788f33a585a84503476a41d9d3eb6c7b6dc65e1dd3fa
6
+ metadata.gz: 7f34ec86d849b6e8f1d3484238ac57a56142d4a9b4744048109dd515a0d38d8231c727d81951e41045c1333c04eb2d5c5b1d71badff7331a93a9f3977855c247
7
+ data.tar.gz: 108f60886a9b08b084a58ab8152d9a1cb1a4f0c647abffbfc614eee904c9b7892846be940faaec9c8f1afe4848263752cdc516996900180f76bc2b522cbeb2fc
@@ -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)
@@ -1,7 +1,7 @@
1
1
  module FatCore
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- PATCH = 8
4
+ PATCH = 9
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].compact.join('.')
7
7
  end
@@ -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
@@ -204,14 +204,20 @@ describe Range do
204
204
  expect(gaps).to be_empty
205
205
  end
206
206
 
207
- it "should return an gaps at beginning and end" do
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.8
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-01 00:00:00.000000000 Z
11
+ date: 2014-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler