descriptive-statistics 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -53,6 +53,29 @@ stats.skewness #=> 1.188328915820243
53
53
  stats.kurtosis #=> 2.405613966453127
54
54
  ```
55
55
 
56
+ ## Alternative Usage (Not suggested)
57
+ If you want to monkey patch descriptive statistics methods into Enumerable, you can use the following:
58
+
59
+ (e.g. config/initializers/descriptive_statistics_monkey_patch.rb)
60
+ ```ruby
61
+ require 'descriptive-statistics'
62
+
63
+ module Enumerable
64
+ include DescriptiveStatistics::All
65
+
66
+ # Warning: hacky evil meta programming. Required because classes that have already included
67
+ # Enumerable will not otherwise inherit the statistics methods.
68
+ DescriptiveStatistics::All.instance_methods.each do |m|
69
+ define_method(m, DescriptiveStatistics::All.instance_method(m))
70
+ end
71
+ end
72
+ ```
73
+
74
+ Then you can use these methods directly on Arrays:
75
+ ```ruby
76
+ [1,1,2,3,10].mean #=> 3.4
77
+ ```
78
+
56
79
  ## Contributing
57
80
 
58
81
  1. Fork it
@@ -1,16 +1,10 @@
1
1
  require 'forwardable'
2
2
  require "descriptive-statistics/version"
3
- require 'descriptive-statistics/central-tendency'
4
- require 'descriptive-statistics/dispersion'
5
- require 'descriptive-statistics/spread'
6
- require 'descriptive-statistics/shape'
3
+ require 'descriptive-statistics/all'
7
4
 
8
5
  class DescriptiveStatistics
9
6
  extend Forwardable
10
- include CentralTendency
11
- include Dispersion
12
- include Spread
13
- include Shape
7
+ include DescriptiveStatistics::All
14
8
 
15
9
  def initialize(data)
16
10
  @data = data
@@ -0,0 +1,13 @@
1
+ require 'descriptive-statistics/central-tendency'
2
+ require 'descriptive-statistics/dispersion'
3
+ require 'descriptive-statistics/spread'
4
+ require 'descriptive-statistics/shape'
5
+
6
+ class DescriptiveStatistics
7
+ module All
8
+ include CentralTendency
9
+ include Dispersion
10
+ include Shape
11
+ include Spread
12
+ end
13
+ end
@@ -1,5 +1,5 @@
1
1
  module Descriptive
2
2
  module Statistics
3
- VERSION = "1.3.2"
3
+ VERSION = "1.3.3"
4
4
  end
5
5
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe DescriptiveStatistics::All do
4
+ it 'should include all stats modules' do
5
+ [DescriptiveStatistics::Spread, DescriptiveStatistics::Shape, DescriptiveStatistics::Dispersion,
6
+ DescriptiveStatistics::CentralTendency].each do |ancestor_module|
7
+ DescriptiveStatistics::All.ancestors.should include(ancestor_module)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe DescriptiveStatistics do
4
+ it 'should allow hacky monkey patches to add methods to structures like arrays' do
5
+ module Enumerable
6
+ include DescriptiveStatistics::All
7
+
8
+ # Warning: hacky evil meta programming. Required to have classes that include array get the methods too.
9
+ DescriptiveStatistics::All.instance_methods.each do |m|
10
+ define_method(m, DescriptiveStatistics::All.instance_method(m))
11
+ end
12
+ end
13
+
14
+ [1,2,3].mean.should == 2
15
+ end
16
+ end
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: 1.3.2
4
+ version: 1.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -58,15 +58,18 @@ files:
58
58
  - Rakefile
59
59
  - descriptive-statistics.gemspec
60
60
  - lib/descriptive-statistics.rb
61
+ - lib/descriptive-statistics/all.rb
61
62
  - lib/descriptive-statistics/central-tendency.rb
62
63
  - lib/descriptive-statistics/dispersion.rb
63
64
  - lib/descriptive-statistics/shape.rb
64
65
  - lib/descriptive-statistics/spread.rb
65
66
  - lib/descriptive-statistics/version.rb
67
+ - spec/lib/descriptive-statistics/all_spec.rb
66
68
  - spec/lib/descriptive-statistics/central_tendency_spec.rb
67
69
  - spec/lib/descriptive-statistics/dispersion_spec.rb
68
70
  - spec/lib/descriptive-statistics/shape_spec.rb
69
71
  - spec/lib/descriptive-statistics/spread_spec.rb
72
+ - spec/lib/descriptive_statistics_spec.rb
70
73
  - spec/spec_helper.rb
71
74
  homepage: https://github.com/jtescher/descriptive-statistics
72
75
  licenses: []
@@ -82,7 +85,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
82
85
  version: '0'
83
86
  segments:
84
87
  - 0
85
- hash: 4587157788516746300
88
+ hash: 4013925154357511722
86
89
  required_rubygems_version: !ruby/object:Gem::Requirement
87
90
  none: false
88
91
  requirements:
@@ -91,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
94
  version: '0'
92
95
  segments:
93
96
  - 0
94
- hash: 4587157788516746300
97
+ hash: 4013925154357511722
95
98
  requirements: []
96
99
  rubyforge_project:
97
100
  rubygems_version: 1.8.24
@@ -101,8 +104,10 @@ summary: Simply calculate descriptive statistics such as measures of central ten
101
104
  (e.g. mean,median, mode), dispersion (e.g. range and quartiles), and spread (e.g
102
105
  variance and standard deviation)
103
106
  test_files:
107
+ - spec/lib/descriptive-statistics/all_spec.rb
104
108
  - spec/lib/descriptive-statistics/central_tendency_spec.rb
105
109
  - spec/lib/descriptive-statistics/dispersion_spec.rb
106
110
  - spec/lib/descriptive-statistics/shape_spec.rb
107
111
  - spec/lib/descriptive-statistics/spread_spec.rb
112
+ - spec/lib/descriptive_statistics_spec.rb
108
113
  - spec/spec_helper.rb