underglow 0.1.0 → 0.1.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.
- data/lib/underglow/extensions/array.rb +14 -0
- data/lib/underglow/version.rb +1 -1
- data/lib/underglow.rb +1 -0
- data/spec/extensions/array_spec.rb +34 -0
- data/underglow.gemspec +4 -2
- metadata +5 -3
@@ -0,0 +1,14 @@
|
|
1
|
+
class Array
|
2
|
+
def bucketize(count)
|
3
|
+
raise ArgumentError unless count.kind_of? Fixnum
|
4
|
+
|
5
|
+
count = count.to_i
|
6
|
+
|
7
|
+
return self if count <= 0
|
8
|
+
|
9
|
+
j = length / count.to_f
|
10
|
+
result = each_with_index.chunk { |_, i| (i / j).floor }.map { |_, v| v.map(&:first) }
|
11
|
+
result << [] until result.length == count
|
12
|
+
result
|
13
|
+
end
|
14
|
+
end
|
data/lib/underglow/version.rb
CHANGED
data/lib/underglow.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Array" do
|
4
|
+
describe '#bucketize' do
|
5
|
+
it "splits array into number of buckets" do
|
6
|
+
bucketized = [4, 5, 6, 7].bucketize(2)
|
7
|
+
bucketized.should == [[4, 5], [6, 7]]
|
8
|
+
end
|
9
|
+
|
10
|
+
it "splits array into buckets with uneven counts if necessary" do
|
11
|
+
bucketized = [4, 5, 6, 7, 8].bucketize(3)
|
12
|
+
bucketized.should == [[4, 5], [6, 7], [8]]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "works with just one bucket" do
|
16
|
+
bucketized = [4, 5, 6, 7].bucketize(1)
|
17
|
+
bucketized.should == [[4, 5, 6, 7]]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can handles empty buckets" do
|
21
|
+
bucketized = [4, 5, 6, 7].bucketize(5)
|
22
|
+
bucketized.should == [[4], [5], [6], [7], []]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns array if no buckets" do
|
26
|
+
bucketized = [4, 5, 6, 7].bucketize(0)
|
27
|
+
bucketized.should == [4, 5, 6, 7]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "raises argument error if not given an integer" do
|
31
|
+
lambda { [4, 5, 6].bucketize("foo") }.should raise_error(ArgumentError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/underglow.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "underglow"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["James Hu"]
|
12
|
-
s.date = "2013-
|
12
|
+
s.date = "2013-07-13"
|
13
13
|
s.description = "A library that makes life easier."
|
14
14
|
s.email = "axsuul@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/underglow/capistrano/deploy/rake.rb",
|
32
32
|
"lib/underglow/capistrano/deploy/unicorn.rb",
|
33
33
|
"lib/underglow/capistrano/helpers.rb",
|
34
|
+
"lib/underglow/extensions/array.rb",
|
34
35
|
"lib/underglow/extensions/string.rb",
|
35
36
|
"lib/underglow/extensions/symbol.rb",
|
36
37
|
"lib/underglow/rails/environment.rb",
|
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
|
|
38
39
|
"lib/underglow/tasks/system.rake",
|
39
40
|
"lib/underglow/tasks/thin.rake",
|
40
41
|
"lib/underglow/version.rb",
|
42
|
+
"spec/extensions/array_spec.rb",
|
41
43
|
"spec/extensions/string_spec.rb",
|
42
44
|
"spec/extensions/symbol_spec.rb",
|
43
45
|
"spec/spec_helper.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: underglow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- lib/underglow/capistrano/deploy/rake.rb
|
98
98
|
- lib/underglow/capistrano/deploy/unicorn.rb
|
99
99
|
- lib/underglow/capistrano/helpers.rb
|
100
|
+
- lib/underglow/extensions/array.rb
|
100
101
|
- lib/underglow/extensions/string.rb
|
101
102
|
- lib/underglow/extensions/symbol.rb
|
102
103
|
- lib/underglow/rails/environment.rb
|
@@ -104,6 +105,7 @@ files:
|
|
104
105
|
- lib/underglow/tasks/system.rake
|
105
106
|
- lib/underglow/tasks/thin.rake
|
106
107
|
- lib/underglow/version.rb
|
108
|
+
- spec/extensions/array_spec.rb
|
107
109
|
- spec/extensions/string_spec.rb
|
108
110
|
- spec/extensions/symbol_spec.rb
|
109
111
|
- spec/spec_helper.rb
|
@@ -123,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
125
|
version: '0'
|
124
126
|
segments:
|
125
127
|
- 0
|
126
|
-
hash:
|
128
|
+
hash: 4594569153630898161
|
127
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
130
|
none: false
|
129
131
|
requirements:
|