descriptive_statistics 2.2.0 → 2.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e309fdf859185630fa3f8766b51c32411b748190
4
- data.tar.gz: 2852dd323dec053aea7afaa813456ee350f13ab1
3
+ metadata.gz: e981e428e540b52e30081acb0032710f554d3e21
4
+ data.tar.gz: 77d7e94da2d230552ca0ce4d5207f89c1a5f09a4
5
5
  SHA512:
6
- metadata.gz: a4d7de2fbb8be9a1b7cfd08e18b643fd7186c1b3914b2b73dd753086e5c22cd47e14e3b03b2933d7aeff9d4a0f6d68034d3402da37f97cfa1892dfef79b39901
7
- data.tar.gz: cbd99a2b32aa960ae41643dedee7f51dd3d60a1473ba239742b417ee2f3971df29fe9ec0193091d0b5c7b2ad8f9f7aa834a9eb4a83cb1fa487c05fca1306a775
6
+ metadata.gz: b6cdc1e2960d9d0757d7c9f9a6376f157e00993d2ae3ce750e1e10f63cbc69de989bb9e7e0c60eb860ad890ec3822a8c4abe739edd1859b82ee3942a6d4fe97f
7
+ data.tar.gz: e2c266d82340739389517c43b32423226209320f7757245eaecf5258b614f2b507d870e2be4f2bbb33f717fb13d566924082a13e25f1af0f451d61c9ab9997a2
@@ -2,6 +2,8 @@ module DescriptiveStatistics
2
2
 
3
3
  class << self
4
4
 
5
+ attr_accessor :empty_collection_default_value
6
+
5
7
  DescriptiveStatistics.instance_methods.each do |m|
6
8
  define_method(m, DescriptiveStatistics.instance_method(m))
7
9
  end
@@ -1,7 +1,7 @@
1
1
  module DescriptiveStatistics
2
2
  def mean(collection = self)
3
3
  values = Support::convert(collection)
4
- return unless values.size > 0
4
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
5
5
 
6
6
  values.sum / values.number
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module DescriptiveStatistics
2
2
  def median(collection = self)
3
3
  values = Support::convert(collection)
4
- return unless values.size > 0
4
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
5
5
 
6
6
  values.percentile(50)
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module DescriptiveStatistics
2
2
  def percentile(p, collection = self)
3
3
  values = Support::convert(collection)
4
- return unless values.size > 0
4
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
5
5
 
6
6
  return values.first unless values.size > 1
7
7
 
@@ -2,7 +2,7 @@ module DescriptiveStatistics
2
2
  # percent of cases that are at or below a score
3
3
  def percentile_rank(p, collection = self)
4
4
  values = Support::convert(collection)
5
- return unless values.size > 0
5
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
6
6
 
7
7
  return (((values.sort.rindex{ |x| x <= p } || -1.0) + 1.0)) / values.number * 100.0
8
8
  end
@@ -1,7 +1,7 @@
1
1
  module DescriptiveStatistics
2
2
  def range(collection = self)
3
3
  values = Support::convert(collection)
4
- return unless values.size > 0
4
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
5
5
 
6
6
  values.max - values.min
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module DescriptiveStatistics
2
2
  def standard_deviation(collection = self)
3
3
  values = Support::convert(collection)
4
- return unless values.size > 0
4
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
5
5
 
6
6
  Math.sqrt(values.variance)
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module DescriptiveStatistics
2
2
  def sum(collection = self)
3
3
  values = Support::convert(collection)
4
- return unless values.size > 0
4
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
5
5
 
6
6
  return values.inject(:+)
7
7
  end
@@ -1,7 +1,7 @@
1
1
  module DescriptiveStatistics
2
2
  def variance(collection = self)
3
3
  values = Support::convert(collection)
4
- return unless values.size > 0
4
+ return DescriptiveStatistics.empty_collection_default_value unless values.size > 0
5
5
 
6
6
  mean = values.mean
7
7
  values.map{ |sample| (mean - sample) ** 2 }.inject(:+) / values.number
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: descriptive_statistics
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derrick Parkhurst
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2014-09-03 00:00:00.000000000 Z
15
+ date: 2014-09-05 00:00:00.000000000 Z
16
16
  dependencies: []
17
17
  description: Adds descriptive statistics methods to Enumerable module for use on collections
18
18
  or Numeric data