mean 0.0.2

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/History.txt ADDED
@@ -0,0 +1,9 @@
1
+ === 0.0.1 2009-09-21
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
5
+
6
+ === 0.0.2 2009-09-21
7
+
8
+ * 1 major enhancement:
9
+ * Gem should actually work
data/Manifest.txt ADDED
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/mean.rb
7
+ lib/mean/sum.rb
8
+ lib/mean/mean.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ spec/mean_spec.rb
13
+ spec/spec.opts
14
+ spec/spec_helper.rb
15
+ tasks/rspec.rake
data/PostInstall.txt ADDED
@@ -0,0 +1,3 @@
1
+ Happy Meaning!
2
+
3
+
data/README.rdoc ADDED
@@ -0,0 +1,49 @@
1
+ = mean
2
+
3
+ * http://github.com/bryanwoods/mean
4
+
5
+ == DESCRIPTION:
6
+
7
+ Monkeypatches Ruby's Array Class to add "sum" and "mean" methods.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * Find the mean of an array of integers
12
+
13
+ ** BONUSWTFBBQ **
14
+
15
+ * Also find the sum of an array of integers
16
+
17
+ == SYNOPSIS:
18
+
19
+ [1337, 1337, 31337].mean
20
+ => 11337
21
+
22
+ ** BONUS FUNCTIONALITY **
23
+
24
+ [1, 2, 3].sum
25
+ => 6
26
+
27
+ == INSTALL:
28
+
29
+ sudo gem install mean
30
+
31
+ == LICENSE:
32
+
33
+ (The WTFPL License)
34
+
35
+ Copyright (c) 2009 Bryan Woods
36
+
37
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
38
+ Version 2, December 2004
39
+
40
+ Copyright (C) 2004 Sam Hocevar
41
+ 14 rue de Plaisance, 75014 Paris, France
42
+ Everyone is permitted to copy and distribute verbatim or modified
43
+ copies of this license document, and changing it is allowed as long
44
+ as the name is changed.
45
+
46
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
47
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
48
+
49
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/mean'
6
+ require 'mean/mean'
7
+ require 'mean/sum'
8
+
9
+ Hoe.plugin :newgem
10
+ # Hoe.plugin :website
11
+ # Hoe.plugin :cucumberfeatures
12
+
13
+ # Generate all the Rake tasks
14
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
15
+ $hoe = Hoe.spec 'mean' do
16
+ self.developer 'Bryan Woods', 'bryanwoods4e@gmail.com'
17
+ self.post_install_message = 'PostInstall.txt'
18
+ self.rubyforge_name = self.name
19
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
20
+
21
+ end
22
+
23
+ require 'newgem/tasks'
24
+ Dir['tasks/**/*.rake'].each { |t| load t }
25
+
26
+ # TODO - want other tests/tasks run by default? Add them to the list
27
+ # remove_task :default
28
+ # task :default => [:spec, :features]
data/lib/mean/mean.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def mean
3
+ sum / size
4
+ end
5
+ end
data/lib/mean/sum.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def sum
3
+ inject(nil){|sum, x| sum ? sum + x : x}
4
+ end
5
+ end
data/lib/mean.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Mean
5
+ VERSION = '0.0.2'
6
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/mean.rb'}"
9
+ puts "Loading mean gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/spec/mean_spec.rb ADDED
@@ -0,0 +1,100 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ require "mean/sum"
4
+ require "mean/mean"
5
+
6
+ describe "Sum and Array" do
7
+
8
+ it "should find the sum of a given array" do
9
+ array_sum = [1, 2, 3].sum
10
+ array_sum.should == 6
11
+ end
12
+
13
+ it "should be able to sum big numbers" do
14
+ bignum_one = 1337 ** 1337
15
+ bignum_two = 1337 * 1337
16
+ bignum_three = 1337
17
+ bignum_sum = [(1337 ** 1337), (1337 * 1337), 1337].sum
18
+ bignum_sum.should == bignum_one + bignum_two + bignum_three
19
+ end
20
+
21
+ it "should be able to sum fractions" do
22
+ fraction_one = 22/7
23
+ fraction_two = 1/3
24
+ fraction_three = 81/9
25
+ fraction_sum = [fraction_one, fraction_two, fraction_three].sum
26
+ fraction_sum.should == fraction_one + fraction_two + fraction_three
27
+ end
28
+
29
+ it "should be able to sum decimals" do
30
+ decimal_one = 0.001
31
+ decimal_two = 62.32424
32
+ decimal_three = 0.75
33
+ decimal_sum = [decimal_one, decimal_two, decimal_three].sum
34
+ decimal_sum.should == decimal_one + decimal_two + decimal_three
35
+ end
36
+
37
+ it "should be able to add negative numbers" do
38
+ negative_number_one = -3
39
+ negative_number_two = -27.3
40
+ negative_number_three = -80
41
+ negative_number_sum = [negative_number_one, negative_number_two, negative_number_three].sum
42
+ negative_number_sum.should == negative_number_one + negative_number_two + negative_number_three
43
+ end
44
+
45
+ it "should find the mean of a given array" do
46
+ array_mean = [1, 2, 3].mean
47
+ array_mean.should == 2
48
+ end
49
+
50
+ it "should be able to find the mean of big numbers" do
51
+ bignum_one = 1337 ** 1337
52
+ bignum_two = 1337 * 1337
53
+ bignum_three = 1337
54
+ bignum_mean = [(1337 ** 1337), (1337 * 1337), 1337].mean
55
+ bignum_sum = bignum_one + bignum_two + bignum_three
56
+ bignum_size = [bignum_one, bignum_two, bignum_three].size
57
+ bignum_mean.should == bignum_sum / bignum_size
58
+ end
59
+
60
+ it "should be able to find the mean of fractions" do
61
+ fraction_one = 22/7
62
+ fraction_two = 1/3
63
+ fraction_three = 81/9
64
+ fraction_mean = [22/7, 1/3, 81/9].mean
65
+ fraction_sum = [fraction_one, fraction_two, fraction_three].sum
66
+ fraction_size = [fraction_one, fraction_two, fraction_three].size
67
+ fraction_mean.should == fraction_sum / fraction_size
68
+ end
69
+
70
+ it "should be able to find the mean of decimals" do
71
+ decimal_one = 0.001
72
+ decimal_two = 62.32424
73
+ decimal_three = 0.75
74
+ decimal_mean = [0.001, 62.32424, 0.75].mean
75
+ decimal_sum = [decimal_one, decimal_two, decimal_three].sum.to_f
76
+ decimal_size = [decimal_one, decimal_two, decimal_three].size
77
+ decimal_mean.should == decimal_sum / decimal_size
78
+ end
79
+
80
+ it "should be able to find the mean of negative numbers" do
81
+ negative_number_one = -3
82
+ negative_number_two = -27.3
83
+ negative_number_three = -80
84
+ negative_number_mean = [-3, -27.3, -80].mean
85
+ negative_number_sum = [negative_number_one, negative_number_two, negative_number_three].sum
86
+ negative_number_size = [negative_number_one, negative_number_two, negative_number_three].size
87
+ negative_number_mean.should == negative_number_sum / negative_number_size
88
+ end
89
+
90
+ it "should concatenate strings with sum" do
91
+ non_number = ["B", "O", "N", "U", "S"]
92
+ non_number.sum.should == "BONUS"
93
+ end
94
+
95
+ it "should not find the mean of non-numbers" do
96
+ non_number = ["B", "O", "N", "U", "S"]
97
+ non_number.mean.should rescue NoMethodError
98
+ end
99
+
100
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'mean'
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mean
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Bryan Woods
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-21 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.2
24
+ version:
25
+ description: Monkeypatches Ruby's Array Class to add "sum" and "mean" methods.
26
+ email:
27
+ - bryanwoods4e@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - PostInstall.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - PostInstall.txt
40
+ - README.rdoc
41
+ - Rakefile
42
+ - lib/mean.rb
43
+ - lib/mean/sum.rb
44
+ - lib/mean/mean.rb
45
+ - script/console
46
+ - script/destroy
47
+ - script/generate
48
+ - spec/mean_spec.rb
49
+ - spec/spec.opts
50
+ - spec/spec_helper.rb
51
+ - tasks/rspec.rake
52
+ has_rdoc: true
53
+ homepage: http://github.com/bryanwoods/mean
54
+ licenses: []
55
+
56
+ post_install_message: PostInstall.txt
57
+ rdoc_options:
58
+ - --main
59
+ - README.rdoc
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: mean
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Monkeypatches Ruby's Array Class to add "sum" and "mean" methods.
81
+ test_files: []
82
+