descriptive_statistics 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,2 @@
1
-
2
- require 'descriptive_statistics/number.rb'
3
- require 'descriptive_statistics/sum.rb'
4
- require 'descriptive_statistics/mean.rb'
5
- require 'descriptive_statistics/median.rb'
6
- require 'descriptive_statistics/variance.rb'
7
- require 'descriptive_statistics/standard_deviation.rb'
8
- require 'descriptive_statistics/percentile.rb'
9
-
1
+ require "descriptive_statistics/safe"
2
+ require "descriptive_statistics/enumerable_extension"
@@ -0,0 +1,11 @@
1
+ module Enumerable
2
+ include DescriptiveStatistics
3
+
4
+ # This is necessary because otherwise objects which
5
+ # have already included Enumerable (such as Array) won't
6
+ # be able to access DescriptiveStatistics's methods.
7
+ # It is an evil hack though :-/
8
+ DescriptiveStatistics.instance_methods.each do |m|
9
+ define_method(m, DescriptiveStatistics.instance_method(m))
10
+ end
11
+ end
@@ -1,7 +1,5 @@
1
- module Enumerable
2
-
1
+ module DescriptiveStatistics
3
2
  def mean
4
3
  self.sum / self.number
5
4
  end
6
-
7
5
  end
@@ -1,7 +1,5 @@
1
- module Enumerable
2
-
1
+ module DescriptiveStatistics
3
2
  def median
4
3
  self.percentile(50)
5
4
  end
6
-
7
5
  end
@@ -1,7 +1,5 @@
1
- module Enumerable
2
-
1
+ module DescriptiveStatistics
3
2
  def number
4
3
  self.size.to_f
5
4
  end
6
-
7
5
  end
@@ -1,5 +1,4 @@
1
- module Enumerable
2
-
1
+ module DescriptiveStatistics
3
2
  def percentile(p)
4
3
  sorted = self.sort
5
4
  return sorted[-1].to_f if p == 100
@@ -10,5 +9,4 @@ module Enumerable
10
9
  upper = sorted[lrank+1].to_f
11
10
  lower + (upper - lower) * d
12
11
  end
13
-
14
12
  end
@@ -0,0 +1,7 @@
1
+ require 'descriptive_statistics/number.rb'
2
+ require 'descriptive_statistics/sum.rb'
3
+ require 'descriptive_statistics/mean.rb'
4
+ require 'descriptive_statistics/median.rb'
5
+ require 'descriptive_statistics/variance.rb'
6
+ require 'descriptive_statistics/standard_deviation.rb'
7
+ require 'descriptive_statistics/percentile.rb'
@@ -1,7 +1,5 @@
1
- module Enumerable
2
-
1
+ module DescriptiveStatistics
3
2
  def standard_deviation
4
3
  Math.sqrt(self.variance)
5
4
  end
6
-
7
5
  end
@@ -1,7 +1,5 @@
1
- module Enumerable
2
-
1
+ module DescriptiveStatistics
3
2
  def sum
4
3
  return self.inject(:+)
5
4
  end
6
-
7
5
  end
@@ -1,8 +1,6 @@
1
- module Enumerable
2
-
1
+ module DescriptiveStatistics
3
2
  def variance
4
3
  mean = self.mean
5
4
  self.map{ |sample| (mean - sample) ** 2 }.inject(:+) / self.number
6
5
  end
7
-
8
6
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: descriptive_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Derrick Parkhurst
9
+ - Gregory Brown
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-06-15 00:00:00.000000000Z
13
+ date: 2012-09-18 00:00:00.000000000Z
13
14
  dependencies: []
14
15
  description: Adds descriptive statistics methods to Enumerable for use on collections
15
16
  email: derrick.parkhurst@gmail.com
@@ -17,10 +18,12 @@ executables: []
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
21
+ - lib/descriptive_statistics/enumerable_extension.rb
20
22
  - lib/descriptive_statistics/mean.rb
21
23
  - lib/descriptive_statistics/median.rb
22
24
  - lib/descriptive_statistics/number.rb
23
25
  - lib/descriptive_statistics/percentile.rb
26
+ - lib/descriptive_statistics/safe.rb
24
27
  - lib/descriptive_statistics/standard_deviation.rb
25
28
  - lib/descriptive_statistics/sum.rb
26
29
  - lib/descriptive_statistics/variance.rb