gorillib 0.1.9 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9
1
+ 0.1.11
data/gorillib.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "gorillib"
8
- s.version = "0.1.9"
8
+ s.version = "0.1.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Infochimps"]
12
- s.date = "2012-02-28"
12
+ s.date = "2012-06-22"
13
13
  s.description = "Gorillib: infochimps lightweight subset of ruby convenience methods"
14
14
  s.email = "coders@infochimps.org"
15
15
  s.extra_rdoc_files = [
@@ -27,10 +27,14 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "gorillib.gemspec",
29
29
  "lib/gorillib.rb",
30
+ "lib/gorillib/array/average.rb",
30
31
  "lib/gorillib/array/compact_blank.rb",
31
32
  "lib/gorillib/array/deep_compact.rb",
32
33
  "lib/gorillib/array/extract_options.rb",
33
34
  "lib/gorillib/array/random.rb",
35
+ "lib/gorillib/array/sorted_median.rb",
36
+ "lib/gorillib/array/sorted_percentile.rb",
37
+ "lib/gorillib/array/sorted_sample.rb",
34
38
  "lib/gorillib/base.rb",
35
39
  "lib/gorillib/datetime/flat.rb",
36
40
  "lib/gorillib/datetime/parse.rb",
@@ -87,8 +91,12 @@ Gem::Specification.new do |s|
87
91
  "lib/gorillib/struct/hashlike_iteration.rb",
88
92
  "notes/fancy_hashes_and_receivers.textile",
89
93
  "notes/hash_rdocs.textile",
94
+ "spec/array/average_spec.rb",
90
95
  "spec/array/compact_blank_spec.rb",
91
96
  "spec/array/extract_options_spec.rb",
97
+ "spec/array/sorted_median_spec.rb",
98
+ "spec/array/sorted_percentile_spec.rb",
99
+ "spec/array/sorted_sample_spec.rb",
92
100
  "spec/datetime/flat_spec.rb",
93
101
  "spec/datetime/parse_spec.rb",
94
102
  "spec/dsl_object_spec.rb",
@@ -142,7 +150,7 @@ Gem::Specification.new do |s|
142
150
  s.require_paths = ["lib"]
143
151
  s.rubygems_version = "1.8.15"
144
152
  s.summary = "include only what you need. No dependencies, no creep"
145
- s.test_files = ["spec/array/compact_blank_spec.rb", "spec/array/extract_options_spec.rb", "spec/datetime/flat_spec.rb", "spec/datetime/parse_spec.rb", "spec/dsl_object_spec.rb", "spec/enumerable/sum_spec.rb", "spec/hash/compact_spec.rb", "spec/hash/deep_compact_spec.rb", "spec/hash/deep_merge_spec.rb", "spec/hash/indifferent_access_spec.rb", "spec/hash/keys_spec.rb", "spec/hash/reverse_merge_spec.rb", "spec/hash/slice_spec.rb", "spec/hash/zip_spec.rb", "spec/hashlike/behave_same_as_hash_spec.rb", "spec/hashlike/deep_hash_spec.rb", "spec/hashlike/hashlike_behavior_spec.rb", "spec/hashlike/hashlike_via_accessors_spec.rb", "spec/hashlike_spec.rb", "spec/logger/log_spec.rb", "spec/metaprogramming/aliasing_spec.rb", "spec/metaprogramming/cattr_accessor_spec.rb", "spec/metaprogramming/class_attribute_spec.rb", "spec/metaprogramming/delegation_spec.rb", "spec/metaprogramming/mattr_accessor_spec.rb", "spec/metaprogramming/singleton_class_spec.rb", "spec/numeric/clamp_spec.rb", "spec/object/blank_spec.rb", "spec/object/try_dup_spec.rb", "spec/object/try_spec.rb", "spec/receiver/acts_as_hash_spec.rb", "spec/receiver_spec.rb", "spec/spec_helper.rb", "spec/string/constantize_spec.rb", "spec/string/human_spec.rb", "spec/string/inflections_spec.rb", "spec/string/inflector_test_cases.rb", "spec/string/truncate_spec.rb", "spec/struct/acts_as_hash_fuzz_spec.rb", "spec/struct/acts_as_hash_spec.rb", "spec/support/hashlike_fuzzing_helper.rb", "spec/support/hashlike_helper.rb", "spec/support/hashlike_struct_helper.rb", "spec/support/hashlike_via_delegation.rb", "spec/support/kcode_test_helper.rb", "spec/support/matchers/be_array_eql.rb", "spec/support/matchers/be_hash_eql.rb", "spec/support/matchers/enumerate_method.rb", "spec/support/matchers/evaluate_to_true.rb"]
153
+ s.test_files = ["spec/array/average_spec.rb", "spec/array/compact_blank_spec.rb", "spec/array/extract_options_spec.rb", "spec/array/sorted_median_spec.rb", "spec/array/sorted_percentile_spec.rb", "spec/array/sorted_sample_spec.rb", "spec/datetime/flat_spec.rb", "spec/datetime/parse_spec.rb", "spec/dsl_object_spec.rb", "spec/enumerable/sum_spec.rb", "spec/hash/compact_spec.rb", "spec/hash/deep_compact_spec.rb", "spec/hash/deep_merge_spec.rb", "spec/hash/indifferent_access_spec.rb", "spec/hash/keys_spec.rb", "spec/hash/reverse_merge_spec.rb", "spec/hash/slice_spec.rb", "spec/hash/zip_spec.rb", "spec/hashlike/behave_same_as_hash_spec.rb", "spec/hashlike/deep_hash_spec.rb", "spec/hashlike/hashlike_behavior_spec.rb", "spec/hashlike/hashlike_via_accessors_spec.rb", "spec/hashlike_spec.rb", "spec/logger/log_spec.rb", "spec/metaprogramming/aliasing_spec.rb", "spec/metaprogramming/cattr_accessor_spec.rb", "spec/metaprogramming/class_attribute_spec.rb", "spec/metaprogramming/delegation_spec.rb", "spec/metaprogramming/mattr_accessor_spec.rb", "spec/metaprogramming/singleton_class_spec.rb", "spec/numeric/clamp_spec.rb", "spec/object/blank_spec.rb", "spec/object/try_dup_spec.rb", "spec/object/try_spec.rb", "spec/receiver/acts_as_hash_spec.rb", "spec/receiver_spec.rb", "spec/spec_helper.rb", "spec/string/constantize_spec.rb", "spec/string/human_spec.rb", "spec/string/inflections_spec.rb", "spec/string/inflector_test_cases.rb", "spec/string/truncate_spec.rb", "spec/struct/acts_as_hash_fuzz_spec.rb", "spec/struct/acts_as_hash_spec.rb", "spec/support/hashlike_fuzzing_helper.rb", "spec/support/hashlike_helper.rb", "spec/support/hashlike_struct_helper.rb", "spec/support/hashlike_via_delegation.rb", "spec/support/kcode_test_helper.rb", "spec/support/matchers/be_array_eql.rb", "spec/support/matchers/be_hash_eql.rb", "spec/support/matchers/enumerate_method.rb", "spec/support/matchers/evaluate_to_true.rb"]
146
154
 
147
155
  if s.respond_to? :specification_version then
148
156
  s.specification_version = 3
@@ -0,0 +1,13 @@
1
+ class Array
2
+ #
3
+ # Return the average of my elements.
4
+ #
5
+ # precondition: Each element must be convertible to a float.
6
+ #
7
+ def average
8
+ return nil if empty?
9
+ raise ArgumentError, "Couldn't convert all elements to float!" unless
10
+ all?{|e| e.methods.index :to_f}
11
+ return map(&:to_f).inject(:+) / size
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class Array
2
+ #
3
+ # Returns the middle element of odd-sized arrays. For even arrays,
4
+ # it will return one of the two middle elements. Precisely which is
5
+ # undefined, except that it will consistently return one or the
6
+ # other.
7
+ #
8
+ def sorted_median
9
+ return self[(size - 1) * 0.5]
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ class Array
2
+ #
3
+ # Returns the element at the position closest to the given
4
+ # percentile. For example, sorted_percentile 0.0 will return the
5
+ # first element and sorted_percentile 100.0 will return the last
6
+ # element.
7
+ #
8
+ def sorted_percentile percentile
9
+ return self[(size - 1) * percentile / 100.0]
10
+ end
11
+ end
@@ -0,0 +1,12 @@
1
+ class Array
2
+ #
3
+ # Returns the middle element of odd-sized arrays. For even arrays,
4
+ # it will return one of the two middle elements. Precisely which is
5
+ # undefined, except that it will consistently return one or the
6
+ # other.
7
+ #
8
+ def sorted_sample num
9
+ return [] if empty?
10
+ (1..num).map{|i| self[(size - 1) * i / (num)]}.uniq
11
+ end
12
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require 'gorillib/array/average'
3
+
4
+ describe Array do
5
+ describe '#average' do
6
+ context 'on non-float array element' do
7
+ it 'raises error' do
8
+ expect { [0.0, :b, 1.0].average }.should raise_error(ArgumentError)
9
+ end
10
+ end
11
+
12
+ context 'with empty' do
13
+ it 'returns nil' do
14
+ [].average.should be_nil
15
+ end
16
+ end
17
+
18
+ context 'given a numerical array' do
19
+ it 'returns the average of the elements' do
20
+ (1..10).to_a.average.should == 5.5
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require 'gorillib/array/sorted_median'
3
+
4
+ describe Array do
5
+ describe '#sorted_median' do
6
+ context 'with empty' do
7
+ it 'returns nil' do
8
+ [].sorted_median.should be_nil
9
+ end
10
+ end
11
+
12
+ context 'given any array' do
13
+ it 'returns the middle element of odd-sized arrays' do
14
+ ("a".."y").to_a.sorted_median.should == "m"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require 'gorillib/array/sorted_percentile'
3
+
4
+ describe Array do
5
+ describe '#sorted_percentile' do
6
+ context 'with empty' do
7
+ it 'returns nil' do
8
+ [].sorted_percentile(0.0).should be_nil
9
+ end
10
+ end
11
+
12
+ context 'given any array' do
13
+ it 'returns the element closest to the given percentile' do
14
+ ("a".."y").to_a.sorted_percentile( 0.0).should == "a"
15
+ ("a".."y").to_a.sorted_percentile( 50.0).should == "m"
16
+ ("a".."y").to_a.sorted_percentile(100.0).should == "y"
17
+ end
18
+ end
19
+
20
+ # (Please do not define behavior for two elements equally close to
21
+ # a given percentile.)
22
+
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
+ require 'gorillib/array/sorted_sample'
3
+
4
+ describe Array do
5
+ describe '#sorted_median' do
6
+ context 'with empty' do
7
+ it 'returns an empty array' do
8
+ [].sorted_sample(1).should be_empty
9
+ end
10
+ end
11
+
12
+ context 'given an undersized array' do
13
+ it 'does not return the same element more than once' do
14
+ ("a".."z").to_a.sorted_sample(27).should == ("a".."z").to_a
15
+ end
16
+ end
17
+
18
+ context 'given any array' do
19
+ it ('returns a sample of the given size as close to evenly ' \
20
+ 'distributed over the array as possible') do
21
+ sample = (1..100).to_a.sorted_sample(26)
22
+ deltas = sample[0..-2].zip(sample[1..-1]).map{|a,b| b-a}
23
+ deltas.max.should <= 4
24
+ deltas.min.should >= 3
25
+ end
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gorillib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-28 00:00:00.000000000Z
12
+ date: 2012-06-22 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2185903920 !ruby/object:Gem::Requirement
16
+ requirement: &2165912900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2185903920
24
+ version_requirements: *2165912900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &2185903440 !ruby/object:Gem::Requirement
27
+ requirement: &2165912000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2185903440
35
+ version_requirements: *2165912000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: jeweler
38
- requirement: &2185902960 !ruby/object:Gem::Requirement
38
+ requirement: &2165911060 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.6'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2185902960
46
+ version_requirements: *2165911060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2185902460 !ruby/object:Gem::Requirement
49
+ requirement: &2165910200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.5'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2185902460
57
+ version_requirements: *2165910200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &2185901980 !ruby/object:Gem::Requirement
60
+ requirement: &2165909260 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0.6'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2185901980
68
+ version_requirements: *2165909260
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: cucumber
71
- requirement: &2185901500 !ruby/object:Gem::Requirement
71
+ requirement: &2165908340 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '1'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2185901500
79
+ version_requirements: *2165908340
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: aruba
82
- requirement: &2185901020 !ruby/object:Gem::Requirement
82
+ requirement: &2165907460 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0.4'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2185901020
90
+ version_requirements: *2165907460
91
91
  description: ! 'Gorillib: infochimps lightweight subset of ruby convenience methods'
92
92
  email: coders@infochimps.org
93
93
  executables: []
@@ -106,10 +106,14 @@ files:
106
106
  - VERSION
107
107
  - gorillib.gemspec
108
108
  - lib/gorillib.rb
109
+ - lib/gorillib/array/average.rb
109
110
  - lib/gorillib/array/compact_blank.rb
110
111
  - lib/gorillib/array/deep_compact.rb
111
112
  - lib/gorillib/array/extract_options.rb
112
113
  - lib/gorillib/array/random.rb
114
+ - lib/gorillib/array/sorted_median.rb
115
+ - lib/gorillib/array/sorted_percentile.rb
116
+ - lib/gorillib/array/sorted_sample.rb
113
117
  - lib/gorillib/base.rb
114
118
  - lib/gorillib/datetime/flat.rb
115
119
  - lib/gorillib/datetime/parse.rb
@@ -166,8 +170,12 @@ files:
166
170
  - lib/gorillib/struct/hashlike_iteration.rb
167
171
  - notes/fancy_hashes_and_receivers.textile
168
172
  - notes/hash_rdocs.textile
173
+ - spec/array/average_spec.rb
169
174
  - spec/array/compact_blank_spec.rb
170
175
  - spec/array/extract_options_spec.rb
176
+ - spec/array/sorted_median_spec.rb
177
+ - spec/array/sorted_percentile_spec.rb
178
+ - spec/array/sorted_sample_spec.rb
171
179
  - spec/datetime/flat_spec.rb
172
180
  - spec/datetime/parse_spec.rb
173
181
  - spec/dsl_object_spec.rb
@@ -230,7 +238,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
238
  version: '0'
231
239
  segments:
232
240
  - 0
233
- hash: 387201475316777610
241
+ hash: 4215957582273212195
234
242
  required_rubygems_version: !ruby/object:Gem::Requirement
235
243
  none: false
236
244
  requirements:
@@ -244,8 +252,12 @@ signing_key:
244
252
  specification_version: 3
245
253
  summary: include only what you need. No dependencies, no creep
246
254
  test_files:
255
+ - spec/array/average_spec.rb
247
256
  - spec/array/compact_blank_spec.rb
248
257
  - spec/array/extract_options_spec.rb
258
+ - spec/array/sorted_median_spec.rb
259
+ - spec/array/sorted_percentile_spec.rb
260
+ - spec/array/sorted_sample_spec.rb
249
261
  - spec/datetime/flat_spec.rb
250
262
  - spec/datetime/parse_spec.rb
251
263
  - spec/dsl_object_spec.rb