increments 0.0.3 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/increments.rb +20 -17
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6753a69fd982992e8d84d6213324fd58fe9f91a6
|
4
|
+
data.tar.gz: 9132459069f13c8c68aebcfcac8fcecb30ac077e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00fe7fc4f2a22ee7159ce8fe0ca9b195130d6a65b7bfacb11358814695a18d636a36e7fb57ebc8a110c9eca6849818f60ef8dc6e8b647162a1bfdb845f247458
|
7
|
+
data.tar.gz: 43dd4a84c97ef6e5932aa9dee2b8a65343b244ab974226f1946a578dd72c113b5812b0b8d0003aae9ba32b0feafcf8f4c70f3b0c28fdce07a6fa6c071f34b0cf
|
data/lib/increments.rb
CHANGED
@@ -1,39 +1,42 @@
|
|
1
1
|
module Increments
|
2
|
-
def self.increment(opts={})
|
2
|
+
def self.increment(opts={},&block)
|
3
3
|
options = defaults.merge(opts)
|
4
|
-
validate(options)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
break if max == options[:max]
|
9
|
-
min = [min + options[:increment], options[:max]].min
|
10
|
-
max = [max + options[:increment], options[:max]].min
|
11
|
-
end
|
4
|
+
validate(options,&block)
|
5
|
+
step_enum(options).each do |min|
|
6
|
+
yield(min,range_max(min,options))
|
7
|
+
end
|
12
8
|
end
|
13
9
|
|
14
|
-
def self.decrement(opts={})
|
10
|
+
def self.decrement(opts={},&block)
|
15
11
|
options = defaults.merge(opts)
|
16
|
-
validate(options)
|
12
|
+
validate(options,&block)
|
17
13
|
min, max = [options[:min], options[:max] - options[:increment]+1].max, options[:max]
|
18
14
|
loop do
|
19
15
|
yield(min,max)
|
20
16
|
break if min == options[:min]
|
21
17
|
min = [min - options[:increment], options[:min]].max
|
22
|
-
|
18
|
+
max = [max - options[:increment], options[:min]].max
|
23
19
|
end
|
24
20
|
end
|
25
21
|
|
26
22
|
private
|
27
23
|
|
24
|
+
def self.range_max(min,options)
|
25
|
+
[min + options[:increment]-1,options[:max]].min
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.step_enum(options)
|
29
|
+
(options[:min]..options[:max]).step(options[:increment])
|
30
|
+
end
|
31
|
+
|
28
32
|
def self.defaults
|
29
|
-
{
|
30
|
-
|
31
|
-
|
32
|
-
:increment => 100000
|
33
|
-
}
|
33
|
+
{ :min => 0,
|
34
|
+
:max => 4294967295,
|
35
|
+
:increment => 100000 }
|
34
36
|
end
|
35
37
|
|
36
38
|
def self.validate(options)
|
37
39
|
raise ArgumentError, "Invalid Options: #{options}" if options[:min] > options[:max] || options[:increment] <= 0
|
40
|
+
raise LocalJumpError, "no block given (yield)" unless block_given?
|
38
41
|
end
|
39
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: increments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garren Staubli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Range bound incrementing and decrementing by a specified amount
|
14
14
|
email: gstaubli@demandbase.com
|
@@ -18,7 +18,8 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- lib/increments.rb
|
20
20
|
homepage: https://github.com/gstaubli/increments
|
21
|
-
licenses:
|
21
|
+
licenses:
|
22
|
+
- MIT
|
22
23
|
metadata: {}
|
23
24
|
post_install_message:
|
24
25
|
rdoc_options: []
|