epitools 0.5.22 → 0.5.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe4475f902e2c9728b707d9aa36f2fd8922ea7e0
4
- data.tar.gz: 9c86c70534eb727596fcd018afd7f7c0e4edf258
3
+ metadata.gz: eda0067cd8c9886dabdb526424d410352bce1608
4
+ data.tar.gz: 9bd399762f667a7926582901f9697b8e0a0d3f8e
5
5
  SHA512:
6
- metadata.gz: 7a251525b9b9856f72e0c46644be4126bec6fb23b5cc286acefc9c1f8b23ea613c25c928d0b526baea440de6ba99a8c39a1380ac79306ded00759ae98190a09e
7
- data.tar.gz: 7fb5bc4889d33df063834e767391586cbb2bbf59fc391f5e2eb86f422040f4d8e966864a15dabf7de62d1de752fa7a07b959ce19b380571961f42f306631fdc3
6
+ metadata.gz: 7ccbed66625408ddc19bb3715f4e346dea77a45f07aba06fa6b7da4d7b5d2c444b1765c63469875856545c06ed6262acc87e22db8cc5f43789a01e5f392126bb
7
+ data.tar.gz: d07f39021df1b1d30900ad6e6bde8b0c8f0803875de9395baaa86babac2b749a7436bde521fb90683198bb9e95a849f36d0573a886704e830b133200716a0d6a
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.22
1
+ 0.5.23
@@ -142,9 +142,9 @@ module Enumerable
142
142
  #
143
143
  def sum
144
144
  if block_given?
145
- inject(0) { |total,elem| total + yield(elem) }
145
+ map(&block).reduce(:+)
146
146
  else
147
- inject(0) { |total,elem| total + elem }
147
+ reduce(:+)
148
148
  end
149
149
  end
150
150
 
@@ -153,7 +153,10 @@ module Enumerable
153
153
  #
154
154
  def average
155
155
  count = 0
156
- sum = inject(0) { |total,n| count += 1; total + n }
156
+ sum = 0
157
+
158
+ each { |e| count += 1; sum += e }
159
+
157
160
  sum / count.to_f
158
161
  end
159
162
 
@@ -346,13 +349,17 @@ module Enumerable
346
349
 
347
350
  #
348
351
  # Counts how many instances of each object are in the collection,
349
- # returning a hash.
352
+ # returning a hash. (Also optionally takes a block.)
350
353
  #
351
354
  # eg: [:a, :b, :c, :c, :c, :c].counts #=> {:a=>1, :b=>1, :c=>4}
352
355
  #
353
356
  def counts
354
357
  h = Hash.of_integers
355
- each { |x| h[x] += 1 }
358
+ if block_given?
359
+ each { |x| h[yield x] += 1 }
360
+ else
361
+ each { |x| h[x] += 1 }
362
+ end
356
363
  h
357
364
  end
358
365
  alias_method :counted, :counts
@@ -50,6 +50,21 @@ class String
50
50
  gsub(/\s+/,' ').strip
51
51
  end
52
52
 
53
+ #
54
+ # Convert string to "Title Case" (first letter of each word capitalized)
55
+ #
56
+ def titlecase!
57
+ downcase!
58
+ gsub!(/\b\w/) { |m| m.upcase }
59
+ end
60
+
61
+ #
62
+ # Return a new string converted to "Title Case" (first letter of each word capitalized)
63
+ #
64
+ def titlecase
65
+ dup.titlecase!
66
+ end
67
+
53
68
  #
54
69
  # Remove ANSI color codes.
55
70
  #
@@ -186,6 +186,15 @@ describe String do
186
186
  "\n\n\nblah\n\n\nblah\n\n\n".nice_lines.should == ["blah", "blah"]
187
187
  end
188
188
 
189
+ it "titlecases" do
190
+ "asdf asdfasdf asdf".titlecase.should == "Asdf Asdfasdf Asdf"
191
+ " asdf".titlecase.should == " Asdf"
192
+ "ASDFASDFA SDF".titlecase.should == "Asdfasdfa Sdf"
193
+ s = "asdf asdf"
194
+ s.titlecase!
195
+ s.should == "Asdf Asdf"
196
+ end
197
+
189
198
  it "strips color" do
190
199
  s = "woot!"
191
200
  color_s = s.light_green
@@ -360,7 +369,6 @@ describe Enumerable do
360
369
  end
361
370
 
362
371
  it "selects deeply" do
363
-
364
372
  [[1,2],[3,4]].deep_select {|e| e % 2 == 0 }.should == [[2],[4]]
365
373
  puts
366
374
 
@@ -401,7 +409,7 @@ describe Enumerable do
401
409
  it "sums" do
402
410
  [1,2,3,4,5].sum.should == 15
403
411
  end
404
-
412
+
405
413
  it "averages" do
406
414
  [1,3].average.should == 2.0
407
415
  [1,1,3,3].average.should == 2.0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.22
4
+ version: 0.5.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - epitron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-22 00:00:00.000000000 Z
11
+ date: 2013-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec