statistical_array 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ca25eede413637c5ab1af345dbc0e277eb49d4a
4
+ data.tar.gz: 17c7fadf31feb668a70383032fe666eb81067fce
5
+ SHA512:
6
+ metadata.gz: 4606ffb3c09db94cac19bd38648d17619c930f45dfdea9ad72cccb024cfabb52714a305ea1be940254b72ba6b35d236774c61b0fc350d5a9ebf5a78146188bb1
7
+ data.tar.gz: b954b380caf8d3b9b43283808213644ffb4e5b8a7b8a6aa6b4f6776e0315c3a025885c9eddc7d46b7500254cae29fd80b9109f4f322ee893210e7e9fc08f1ed0
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ _yardoc
7
+ coverage
8
+ doc/
9
+ InstalledFiles
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ statistical_array
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0-p247
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ branches:
5
+ only:
6
+ - master
data/AUTHORS ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012, 2013 Todd A. Jacobs
2
+
3
+ This program is free software: you can redistribute it and/or modify it under
4
+ the terms of the GNU General Public License as published by the Free Software
5
+ Foundation, either version 3 of the License, or (at your option) any later
6
+ version.
7
+
8
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY
9
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10
+ PARTICULAR PURPOSE. See the GNU General Public License for more details.
11
+
12
+ You should have received a copy of the GNU General Public License along with
13
+ this program. If not, see <http://www.gnu.org/licenses/>.
data/COPYING ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012, 2013 Todd A. Jacobs
2
+
3
+ This program is free software: you can redistribute it and/or modify it under
4
+ the terms of the GNU General Public License as published by the Free Software
5
+ Foundation, either version 3 of the License, or (at your option) any later
6
+ version.
7
+
8
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY
9
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10
+ PARTICULAR PURPOSE. See the GNU General Public License for more details.
11
+
12
+ You should have received a copy of the GNU General Public License along with
13
+ this program. If not, see <http://www.gnu.org/licenses/>.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2012, 2013 Todd A. Jacobs
2
+
3
+ This program is free software: you can redistribute it and/or modify it under
4
+ the terms of the GNU General Public License as published by the Free Software
5
+ Foundation, either version 3 of the License, or (at your option) any later
6
+ version.
7
+
8
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY
9
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
10
+ PARTICULAR PURPOSE. See the GNU General Public License for more details.
11
+
12
+ You should have received a copy of the GNU General Public License along with
13
+ this program. If not, see <http://www.gnu.org/licenses/>.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # statistical_array
2
+
3
+ ## Copyright and Licensing
4
+
5
+ ### Copyright Notice
6
+
7
+ The copyright for the software, documentation, and associated files are
8
+ held by the author.
9
+
10
+ Copyright 2012, 2013 Todd A. Jacobs
11
+ All rights reserved.
12
+
13
+ The AUTHORS file is also included in the source tree.
14
+
15
+ ### Software License
16
+
17
+ ![GPLv3 Logo](http://www.gnu.org/graphics/gplv3-88x31.png)
18
+
19
+ The software is licensed under the
20
+ [GPLv3](http://www.gnu.org/copyleft/gpl.html). The LICENSE file is
21
+ included in the source tree.
22
+
23
+ ### README License
24
+
25
+ ![Creative Commons BY-NC-SA
26
+ Logo](http://i.creativecommons.org/l/by-nc-sa/3.0/us/88x31.png)
27
+
28
+ This README is licensed under the [Creative Commons
29
+ Attribution-NonCommercial-ShareAlike 3.0 United States
30
+ License](http://creativecommons.org/licenses/by-nc-sa/3.0/us/).
31
+
32
+ ## Purpose
33
+
34
+ Perform statistical analysis on a custom array class that doesn't
35
+ actually inherit from Array. Provides a template system for flexible
36
+ output.
37
+
38
+ ## Installation and Setup
39
+
40
+ gem install statistical_array
41
+
42
+ ## Usage
43
+
44
+ stats_array <number ...>
45
+
46
+ ## Examples
47
+
48
+ No screenshots here, just samples of what you can expect to see on
49
+ standard output when you run the program.
50
+
51
+ ### Command Line
52
+
53
+ $> stats_array 1 2 3
54
+ Minimum Value: 1
55
+ Maximum Value: 3
56
+ Mean: 2.0
57
+ Median: 2
58
+ Population Standard Deviation: 0.816496580927726
59
+ Sample Standard Deviation: 1.1547005383792515
60
+ Sum of Values: 6
61
+
62
+ ### REPL
63
+
64
+ require 'statistical_array'
65
+ include StatisticalArray
66
+
67
+ ary = StatisticalArray::StatsArray.new [2, 4, 4, 4, 5, 5, 7, 9]
68
+ [ary.median, ary.avg, ary.pop_std]
69
+ #=> [4.5, 5.0, 2.0]
70
+
71
+ ----
72
+
73
+ [Project Home Page](https://github.com/CodeGnome/statistical_array)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/stats_array ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative File.join '..', 'lib', 'statistical_array'
4
+
5
+ unless ARGV.size >= 1
6
+ puts "Usage: #{File.basename $0} <number ...>"
7
+ exit 64
8
+ end
9
+
10
+ include StatisticalArray
11
+ a = StatsArray.new ARGV.map { |i| i.include?('.') ? i.to_f : i.to_i }
12
+ a.print
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'statistical_array/statistical_array'
4
+ require 'statistical_array/aliases'
5
+ require 'statistical_array/array_template'
6
+ require 'statistical_array/version'
7
+
8
+ if __FILE__ == $0
9
+ include StatisticalArray
10
+ a = StatsArray.new ARGV.map { |i| i.include?('.') ? i.to_f : i.to_i }
11
+ a.print
12
+ end
@@ -0,0 +1,10 @@
1
+ module StatisticalArray
2
+ class StatsArray
3
+ alias_method :avg, :mean
4
+ alias_method :min, :minimum
5
+ alias_method :max, :maximum
6
+ alias_method :pop_std, :population_standard_deviation
7
+ alias_method :std_dev, :sample_standard_deviation
8
+ alias_method :total, :sum
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module StatisticalArray
2
+ class ArrayTemplate
3
+ FMT = '
4
+ Minimum Value: %s
5
+ Maximum Value: %s
6
+ Mean: %s
7
+ Median: %s
8
+ Population Standard Deviation: %s
9
+ Sample Standard Deviation: %s
10
+ Sum of Values: %s'.gsub /^\s+/, ''
11
+
12
+ def self.render obj
13
+ values =
14
+ %i[min max mean median pop_std std_dev sum].map { |sym| obj.send sym }
15
+ puts FMT % values
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,43 @@
1
+ module StatisticalArray
2
+ class StatsArray
3
+ def initialize ary, template=nil
4
+ @ary = Array(ary).flatten.compact
5
+ @template_name = template || 'ArrayTemplate'
6
+ end
7
+
8
+ def print
9
+ Kernel.const_get(@template_name.to_s).render self
10
+ end
11
+
12
+ def minimum
13
+ @ary.min
14
+ end
15
+
16
+ def maximum
17
+ @ary.max
18
+ end
19
+
20
+ def mean
21
+ @ary.reduce(:+) / @ary.count.to_f
22
+ end
23
+
24
+ def median
25
+ return nil if @ary.empty?
26
+ n = @ary.size
27
+ a = @ary.sort
28
+ n.odd? ? a[(n-1)/2] : a[(n-1)/2,2].reduce(:+) / 2.0
29
+ end
30
+
31
+ def population_standard_deviation
32
+ Math.sqrt @ary.reduce(0) { |i, j| i + (j - mean)**2 } / @ary.count
33
+ end
34
+
35
+ def sample_standard_deviation
36
+ Math.sqrt @ary.reduce(0) { |i, j| i + (j - mean)**2 } / (@ary.count - 1.5)
37
+ end
38
+
39
+ def sum
40
+ @ary.reduce(:+)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module StatisticalArray
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statistical_array/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'statistical_array'
8
+ spec.version = StatisticalArray::VERSION
9
+ spec.authors = ['Todd A. Jacobs']
10
+ spec.email = ["github.projects@codegnome.org"]
11
+ spec.summary = %q{Generate statistics from a custom array object.}
12
+ spec.description = "Perform statistical analysis on a custom array class " +
13
+ "that doesn't actually inherit from Array. Provides a " +
14
+ "template system for flexible output."
15
+ spec.homepage = "https://github.com/CodeGnome/#{spec.name}"
16
+ spec.license = 'GPLv3'
17
+
18
+ spec.files = `git ls-files`.split($/)
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statistical_array
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Todd A. Jacobs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Perform statistical analysis on a custom array class that doesn't actually
42
+ inherit from Array. Provides a template system for flexible output.
43
+ email:
44
+ - github.projects@codegnome.org
45
+ executables:
46
+ - stats_array
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - .ruby-gemset
52
+ - .ruby-version
53
+ - .travis.yml
54
+ - AUTHORS
55
+ - COPYING
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bin/stats_array
61
+ - lib/statistical_array.rb
62
+ - lib/statistical_array/aliases.rb
63
+ - lib/statistical_array/array_template.rb
64
+ - lib/statistical_array/statistical_array.rb
65
+ - lib/statistical_array/version.rb
66
+ - statistical_array.gemspec
67
+ homepage: https://github.com/CodeGnome/statistical_array
68
+ licenses:
69
+ - GPLv3
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.1.6
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Generate statistics from a custom array object.
91
+ test_files: []