increments 0.0.1 → 0.0.2
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 +4 -4
- data/lib/increments.rb +19 -6
- 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: 13953c6652bbe6087c04964b96b0dfe81f47ae20
|
4
|
+
data.tar.gz: b7977e5f912eb30aaa52a2fc79ab56b02d753f71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb4e981c18190097b98a32d56ce3e0c2f862b1f71ac13bb4a95837f418d858a40ed993c572ce0b547c1b15d3291c94b7e2a5fbcd71f2f2ea5ba159a4b668a230
|
7
|
+
data.tar.gz: f9678777cb8da460669edb227647179ffece37cd113b25e2ea44fe1701c2f764e5dcb282f99ba9731a307ef60c5bb654fbff6ae8ead3edc33a24b244950d918c
|
data/lib/increments.rb
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
module Increments
|
2
2
|
def self.increment(opts={})
|
3
|
-
options =
|
3
|
+
options = defaults.merge(opts)
|
4
4
|
validate(options)
|
5
5
|
min, max = options[:min], [options[:min] + options[:increment]-1, options[:max]].min
|
6
|
-
until max
|
6
|
+
until max > options[:max]
|
7
7
|
yield(min,max)
|
8
|
-
|
9
|
-
|
8
|
+
break if max == options[:max]
|
9
|
+
min = [min + options[:increment], options[:max]].min # Never exceed specified maximum
|
10
|
+
max = [max + options[:increment], options[:max]].min
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
13
|
-
def self.
|
14
|
+
def self.decrement(opts={})
|
15
|
+
options = defaults.merge(opts)
|
16
|
+
validate(options)
|
17
|
+
min, max = [options[:min], options[:max] - options[:increment]+1].max, options[:max]
|
18
|
+
until min < options[:min]
|
19
|
+
yield(min,max)
|
20
|
+
break if min == options[:min]
|
21
|
+
min = [min - options[:increment], options[:min]].max
|
22
|
+
max = [max - options[:increment], options[:min]].max
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.defaults
|
14
27
|
{
|
15
28
|
:min => 0,
|
16
29
|
:max => 4294967295,
|
@@ -18,7 +31,7 @@ module Increments
|
|
18
31
|
}
|
19
32
|
end
|
20
33
|
|
21
|
-
def self.number_of_batches(options)
|
34
|
+
def self.number_of_batches(options=defaults)
|
22
35
|
((options[:max]-options[:min]+1.to_f)/options[:increment]).ceil
|
23
36
|
end
|
24
37
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: increments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garren Staubli
|
@@ -11,7 +11,7 @@ cert_chain: []
|
|
11
11
|
date: 2013-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A gem to facilitate incrementing values
|
14
|
-
email: gstaubli@
|
14
|
+
email: gstaubli@demandbase.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|