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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/increments.rb +19 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 188429ec1753a4277e9f456cb1fb8f3bdb2638b5
4
- data.tar.gz: 2835ab220decdc24a81902eb3b49faa13a3bcdcd
3
+ metadata.gz: 13953c6652bbe6087c04964b96b0dfe81f47ae20
4
+ data.tar.gz: b7977e5f912eb30aaa52a2fc79ab56b02d753f71
5
5
  SHA512:
6
- metadata.gz: 22db10be79d2e4122d56ec735eee499e6b25c60cba7837221d77a1492a432d8e648139548b0a281c6074aa2c0d19238f3176c83bcc9288019c158077c2246a6a
7
- data.tar.gz: 5800c7250c277dcc41efc0a8d1130cb8eb9f19f219e6f234a6790abbdf403ec3dc7ff7554fbaa0b7ea8f47e166cb9608915b06270bde0fbfd91484231d4aacd9
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 = default_options.merge(opts)
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 >= options[:max]
6
+ until max > options[:max]
7
7
  yield(min,max)
8
- min = [min + options[:increment], options[:max]].min # Never exceed specified maximum
9
- max = [max + options[:increment], options[:max]].min
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.default_options
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.1
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@gmail.com
14
+ email: gstaubli@demandbase.com
15
15
  executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []