utilities 0.0.6 → 0.0.7

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/utilities.rb CHANGED
@@ -84,7 +84,7 @@ class Numeric
84
84
  alias_method :percent_of, :percentage_of
85
85
  end
86
86
 
87
- module Utilities
87
+ module Utilities
88
88
  module Statistics
89
89
  # Add each object of the array to each other in order to get the sum, as long as all objects respond to + operator
90
90
  def sum
@@ -96,6 +96,13 @@ module Utilities
96
96
  map{ |i| i**2 }
97
97
  end
98
98
 
99
+ # Return a new array containing the rank of each value
100
+ # Ex: [1, 2, 2, 8, 9] #=> [0.0, 1.5, 1.5, 3.0, 4.0]
101
+ def ranks( already_sorted = false )
102
+ a = already_sorted ? self : sort
103
+ map{ |i| (a.index(i) + a.rindex(i)) / 2.0 }
104
+ end
105
+
99
106
  # Calculate square roots of each item
100
107
  def sqrts
101
108
  map{ |i| i.sqrt }
@@ -115,7 +122,7 @@ module Utilities
115
122
  # Return the variance of self
116
123
  def variance
117
124
  m = mean
118
- inject(0) { |v, x| v += (x - m) ** 2 }
125
+ inject(0) { |v, x| v += (x - m) ** 2 }
119
126
  end
120
127
 
121
128
  # Return the (sample|population) standard deviation of self
@@ -203,6 +210,7 @@ module Utilities
203
210
  :modes => self.modes,
204
211
 
205
212
  # Need to be sorted...
213
+ :ranks => sorted.ranks( true ),
206
214
  :median => sorted.median( true ),
207
215
  :midrange => sorted.midrange( true ),
208
216
  :statistical_range => sorted.statistical_range( true ),
@@ -218,3 +226,28 @@ module Utilities
218
226
  end
219
227
  end
220
228
  end
229
+
230
+ class Array
231
+
232
+ # Returns a copy of self reverse sorted
233
+ def reverse_sort
234
+ dup.rsort!
235
+ end
236
+ alias_method :rsort, :reverse_sort
237
+
238
+ # Reverse sort self
239
+ def reverse_sort!
240
+ sort!{|x,y| y <=> x }
241
+ end
242
+ alias_method :rsort!, :reverse_sort!
243
+
244
+ # Returns a copy of self that includes the Statistics methods
245
+ def to_stat
246
+ dup.to_stat!
247
+ end
248
+
249
+ # Adds the statistics methods to self
250
+ def to_stat!
251
+ extend(Utilities::Statistics)
252
+ end
253
+ end
data/lib/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Utilities
2
2
  MAJOR = 0
3
3
  MINOR = 0
4
- BUILD = 6
4
+ BUILD = 7
5
5
 
6
6
  VERSION = "#{MAJOR}.#{MINOR}.#{BUILD}"
7
7
  end
data/utilities.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  s.name = "utilities"
9
9
  s.version = Utilities::VERSION
10
10
  s.platform = Gem::Platform::RUBY
11
- s.authors = ["Christian Blais"]
12
- s.email = ["christ.blais@gmail.com"]
11
+ s.authors = ["Christian Blais", "Guillaume Malette", "Louis-Mathieu Houle"]
12
+ s.email = ["christ.blais@gmail.com", "gmalette@gmail.com"]
13
13
  s.homepage = "http://github.com/christianblais/utilities"
14
14
  s.summary = "Few utilities include in all my projects"
15
15
  s.description = "Few utilities include in all my projects, including a module for statistics, some to_date and to_time functions as well as intersection method for Range object."
metadata CHANGED
@@ -1,27 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utilities
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christian Blais
14
+ - Guillaume Malette
15
+ - Louis-Mathieu Houle
14
16
  autorequire:
15
17
  bindir: bin
16
18
  cert_chain: []
17
19
 
18
- date: 2011-02-18 00:00:00 -05:00
20
+ date: 2011-02-25 00:00:00 -05:00
19
21
  default_executable:
20
22
  dependencies: []
21
23
 
22
24
  description: Few utilities include in all my projects, including a module for statistics, some to_date and to_time functions as well as intersection method for Range object.
23
25
  email:
24
26
  - christ.blais@gmail.com
27
+ - gmalette@gmail.com
25
28
  executables: []
26
29
 
27
30
  extensions: []