increments 0.0.1

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 +7 -0
  2. data/lib/increments.rb +28 -0
  3. metadata +44 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 188429ec1753a4277e9f456cb1fb8f3bdb2638b5
4
+ data.tar.gz: 2835ab220decdc24a81902eb3b49faa13a3bcdcd
5
+ SHA512:
6
+ metadata.gz: 22db10be79d2e4122d56ec735eee499e6b25c60cba7837221d77a1492a432d8e648139548b0a281c6074aa2c0d19238f3176c83bcc9288019c158077c2246a6a
7
+ data.tar.gz: 5800c7250c277dcc41efc0a8d1130cb8eb9f19f219e6f234a6790abbdf403ec3dc7ff7554fbaa0b7ea8f47e166cb9608915b06270bde0fbfd91484231d4aacd9
data/lib/increments.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Increments
2
+ def self.increment(opts={})
3
+ options = default_options.merge(opts)
4
+ validate(options)
5
+ min, max = options[:min], [options[:min] + options[:increment]-1, options[:max]].min
6
+ until max >= options[:max]
7
+ yield(min,max)
8
+ min = [min + options[:increment], options[:max]].min # Never exceed specified maximum
9
+ max = [max + options[:increment], options[:max]].min
10
+ end
11
+ end
12
+
13
+ def self.default_options
14
+ {
15
+ :min => 0,
16
+ :max => 4294967295,
17
+ :increment => 100000
18
+ }
19
+ end
20
+
21
+ def self.number_of_batches(options)
22
+ ((options[:max]-options[:min]+1.to_f)/options[:increment]).ceil
23
+ end
24
+
25
+ def self.validate(options)
26
+ raise ArgumentError, "Invalid Options: #{options}" if options[:min] > options[:max] || options[:increment] <= 0
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: increments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Garren Staubli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-06-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem to facilitate incrementing values
14
+ email: gstaubli@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/increments.rb
20
+ homepage: http://rubygems.org/gems/increments
21
+ licenses: []
22
+ metadata: {}
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ required_rubygems_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ requirements: []
38
+ rubyforge_project:
39
+ rubygems_version: 2.0.3
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: Increment values
43
+ test_files: []
44
+ has_rdoc: