sixarm_ruby_array_slice 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/CHANGELOG.txt ADDED
@@ -0,0 +1,4 @@
1
+ CHANGELOG
2
+
3
+ 2012-02-01 1.0.0 Publish
4
+
data/INSTALL.txt ADDED
@@ -0,0 +1,32 @@
1
+
2
+ = SixArm.com Ruby Gem Install
3
+
4
+
5
+ First-time users: add our gem certificate and source.
6
+ When you do this once, it works for all our gems.
7
+
8
+ sudo wget http://sixarm.com/sixarm.pem
9
+ sudo gem cert --add sixarm.pem
10
+ sudo gem sources --add http://sixarm.com
11
+
12
+ Install the gem with advanced options.
13
+
14
+ sudo gem install sixarm_ruby_array_slice --test --trust-policy HighSecurity
15
+
16
+
17
+ == Notes
18
+
19
+ Do you have any questions, comments, suggestions, or feedback?
20
+ Let us know, we're happy to help. Our email is sixarm@sixarm.com
21
+
22
+ Do you want to create your own high security gems?
23
+ Learn how at http://www.rubygems.org/read/chapter/21
24
+
25
+ To see your current gem certificate list:
26
+
27
+ sudo gem cert --list
28
+
29
+ Our cert looks like this:
30
+
31
+ /C=US/ST=California/L=San Francisco/O=SixArm/CN=sixarm.com
32
+
data/LICENSE.txt ADDED
@@ -0,0 +1,25 @@
1
+ LICENSE
2
+
3
+ You may choose any of these open source licenses:
4
+
5
+ - Apache License
6
+ - BSD License
7
+ - CreativeCommons License, Non-commercial Share Alike
8
+ - GNU General Public License Version 2 (GPL 2)
9
+ - GNU Lesser General Public License (LGPL)
10
+ - MIT License
11
+ - Perl Artistic License
12
+ - Ruby License
13
+
14
+ The software is provided "as is", without warranty of any kind,
15
+ express or implied, including but not limited to the warranties of
16
+ merchantability, fitness for a particular purpose and noninfringement.
17
+
18
+ In no event shall the authors or copyright holders be liable for any
19
+ claim, damages or other liability, whether in an action of contract,
20
+ tort or otherwise, arising from, out of or in connection with the
21
+ software or the use or other dealings in the software.
22
+
23
+ This license is for the included software that is created by SixArm;
24
+ some of the included software may have its own licenses, copyrights,
25
+ authors, etc. and these do take precedence over the SixArm license.
data/README.rdoc ADDED
@@ -0,0 +1,15 @@
1
+ = SixArm.com » Ruby » Array slices by size and count
2
+
3
+ Author:: Joel Parker Henderson, joel@joelparkerhenderson.com
4
+ Copyright:: Copyright (c) 2006-2012 Joel Parker Henderson
5
+ License:: See LICENSE.txt file
6
+
7
+ Array slice methods:
8
+
9
+ * #slice_by_share: divides an array into a given number of slices
10
+ * #slice_by_size: divides an array into a slices of a given size
11
+
12
+ These methods are extraced from the sixarm_ruby_ramp gem.
13
+
14
+
15
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.1.2
@@ -0,0 +1,70 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README.rdoc
4
+ =end
5
+
6
+
7
+ class Array
8
+
9
+
10
+ # Slice the array into sub-arrays of size _n_.
11
+ #
12
+ # @return [Array<Array<Object>>] slices where each slice has approximately _n_ items
13
+ #
14
+ # If the array divides evenly then each slice has _n_ items:
15
+ #
16
+ # [1,2,3,4,5,6,7,8].slice_by_size(2) => [[1,2],[3,4],[5,6],[7,8]]
17
+ # [1,2,3,4,5,6,7,8].slice_by_size(4) => [[1,2,3,4],[5,6,7,8]]
18
+ #
19
+ # If the array does not divide evenly then the last slice will be smaller:
20
+ #
21
+ # [1,2,3,4,5,6,7,8].slice_by_size(3) => [[1,2,3],[4,5,6],[7,8]]
22
+ #
23
+ # If the array size is small compared to _n_ then the results will be best-attempt:
24
+ #
25
+ # [1,2,3,4,5,6,7,8].slice_by_size(7) => [[1,2,3,4,5,6,7],[8]]
26
+ #
27
+ # Compare #slice_by_share
28
+
29
+ def slice_by_size(size)
30
+ (size.is_a? Integer) or (raise ArgumentError, "size must be an integer")
31
+ (size > 0) or (raise ArgumentError, "size must be > 0")
32
+ arr=[]
33
+ index=0
34
+ while index<length
35
+ arr.push self[index...(index+size)]
36
+ index+=size
37
+ end
38
+ return arr
39
+ end
40
+
41
+
42
+ # Slice the array into _n_ sub-arrays of the same size.
43
+ #
44
+ # @return [Array<Array<Object>>] _n_ slices where each slice is approximately the same size.
45
+ #
46
+ # If the array divides evenly, then each slice has size/n items:
47
+ #
48
+ # [1,2,3,4,5,6,7,8].slice_by_share(2) => [[1,2,3,4],[5,6,7,8]]
49
+ # [1,2,3,4,5,6,7,8].slice_by_share(4) => [[1,2],[3,4],[5,6],[7,8]]
50
+ #
51
+ # If the array does not divide evenly then the latter slices will be smaller:
52
+ #
53
+ # [1,2,3,4,5,6,7,8].slice_by_share(3) => [[1,2,3],[4,5,6],[7,8]]
54
+ #
55
+ # If the array size is small compared to _n_ then the results will be best-attempt:
56
+ #
57
+ # [1,2,3,4,5,6,7,8].slice_by_share(7) => [[1,2],[3,4],[5,6],[7,8],[],[],[]]
58
+ #
59
+ # Compare #slice_by_size
60
+
61
+ def slice_by_share(share)
62
+ (share.is_a? Integer) or (raise ArgumentError, "share must be an integer")
63
+ (share > 0) or (raise ArgumentError, "share must be > 0")
64
+ arr = slice_by_size((length.to_f/share.to_f).ceil)
65
+ while arr.size < share do arr << [] end
66
+ return arr
67
+ end
68
+
69
+
70
+ end
@@ -0,0 +1,105 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test/unit'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_array_slice'
6
+
7
+ class SliceTest < Test::Unit::TestCase
8
+
9
+ A=[1,2,3,4,5,6,7,8]
10
+
11
+ ### #slice_by_size typical use
12
+
13
+ def test_slice_by_size_with_1_count
14
+ assert_equal([[1],[2],[3],[4],[5],[6],[7],[8]], A.slice_by_size(1))
15
+ end
16
+
17
+ def test_slice_by_size_with_balanced_results
18
+ assert_equal([[1,2],[3,4],[5,6],[7,8]], A.slice_by_size(2))
19
+ assert_equal([[1,2,3,4],[5,6,7,8]], A.slice_by_size(4))
20
+ end
21
+
22
+ def test_slice_by_size_with_unbalanced_results
23
+ assert_equal([[1,2,3],[4,5,6],[7,8]], A.slice_by_size(3))
24
+ end
25
+
26
+ def test_slice_by_size_with_very_unbalanced_results
27
+ assert_equal([[1,2,3,4,5,6,7],[8]], A.slice_by_size(7))
28
+ end
29
+
30
+ ### ... atypical
31
+
32
+ def test_slice_by_size_with_empty_input
33
+ assert_equal([],[].slice_by_size(1))
34
+ end
35
+
36
+ def test_slice_by_size_with_0_count
37
+ assert_raise ArgumentError do
38
+ A.slice_by_size(0)
39
+ end
40
+ end
41
+
42
+ def test_slice_by_size_with_negative_count
43
+ assert_raise ArgumentError do
44
+ A.slice_by_size(-1)
45
+ end
46
+ end
47
+
48
+ def test_slice_by_size_with_float_count
49
+ assert_raise ArgumentError do
50
+ A.slice_by_size(1.234)
51
+ end
52
+ end
53
+
54
+ def test_slice_by_size_with_non_numeric_count
55
+ assert_raise ArgumentError do
56
+ A.slice_by_size(1.234)
57
+ end
58
+ end
59
+
60
+ ### #slice_by_share typical use
61
+
62
+ def test_slice_by_share_with_1_count
63
+ assert_equal([[1,2,3,4,5,6,7,8]],A.slice_by_share(1))
64
+ end
65
+
66
+ def test_slice_by_share_with_balanced_results
67
+ assert_equal([[1,2,3,4],[5,6,7,8]], A.slice_by_share(2))
68
+ assert_equal([[1,2],[3,4],[5,6],[7,8]], A.slice_by_share(4))
69
+ end
70
+
71
+ def test_slice_by_share_with_unbalanced_results
72
+ assert_equal([[1,2,3],[4,5,6],[7,8]], A.slice_by_share(3))
73
+ end
74
+
75
+ def test_slice_by_share_with_very_unbalanced_results
76
+ assert_equal([[1,2],[3,4],[5,6],[7,8],[],[],[]], A.slice_by_share(7))
77
+ end
78
+
79
+ ### ...atypical
80
+
81
+ def test_slice_by_share_with_zero_count
82
+ assert_raise ArgumentError do
83
+ A.slice_by_share(0)
84
+ end
85
+ end
86
+
87
+ def test_slice_by_share_with_negative_count
88
+ assert_raise ArgumentError do
89
+ A.slice_by_share(-1)
90
+ end
91
+ end
92
+
93
+ def test_slice_by_share_with_float_count
94
+ assert_raise ArgumentError do
95
+ A.slice_by_share(1.234)
96
+ end
97
+ end
98
+
99
+ def test_slice_by_share_with_non_numeric_count
100
+ assert_raise ArgumentError do
101
+ A.slice_by_share("")
102
+ end
103
+ end
104
+
105
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1 @@
1
+ Su{"�4��b�ۈ�Z��K�[_x�,� �l�������8r�G�ѵ?=V�q�Ńu4O�[�0�g������ͨ�f��P�+S���k��y�@܀�җ��=�=�e�yZ9sN� �(h2/�D��{�����
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_array_slice
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
14
+ Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
15
+ TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZd0ZB
16
+ WURWUVFIRXcxVFlXNGdSbkpoYm1OcApjMk52TVE4d0RRWURWUVFLRXdaVGFY
17
+ aEJjbTB4RXpBUkJnTlZCQU1UQ25OcGVHRnliUzVqYjIwd0hoY05NVEF4Ck1q
18
+ RXpNak15TnpFeldoY05NVE13T1RBNE1qTXlOekV6V2pCZ01Rc3dDUVlEVlFR
19
+ R0V3SlZVekVUTUJFR0ExVUUKQ0JNS1EyRnNhV1p2Y201cFlURVdNQlFHQTFV
20
+ RUJ4TU5VMkZ1SUVaeVlXNWphWE5qYnpFUE1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3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-02-03 00:00:00.000000000 Z
39
+ dependencies: []
40
+ description:
41
+ email: sixarm@sixarm.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gemtest
47
+ - CHANGELOG.txt
48
+ - INSTALL.txt
49
+ - LICENSE.txt
50
+ - Rakefile
51
+ - README.rdoc
52
+ - VERSION
53
+ - lib/sixarm_ruby_array_slice.rb
54
+ - test/sixarm_ruby_array_slice_test.rb
55
+ homepage: http://sixarm.com/
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.15
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: SixArm.com » Ruby » Array slice methods
79
+ test_files:
80
+ - test/sixarm_ruby_array_slice_test.rb
81
+ has_rdoc: true
metadata.gz.sig ADDED
@@ -0,0 +1 @@
1
+ q�+JV���u���(xCj�k�����؄h