addy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create use 1.9.2@addy > /dev/null
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ group :test do
4
+ gem "rspec", "1.3.0"
5
+ gem "cucumber"
6
+ end
7
+
8
+ group :doc do
9
+ gem "yard"
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Allen Madsen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # Addy
2
+
3
+ Allows pretty summations. Instead of writing:
4
+
5
+ (1..5).inject(0) do |memo, num|
6
+ memo + (num**num)
7
+ end
8
+
9
+ You write:
10
+
11
+ sum(1..5) do |num|
12
+ num**num
13
+ end
14
+
15
+ Personally, I would rather write the latter.
16
+
17
+ ## Usage
18
+
19
+ Install the gem:
20
+
21
+ gem install addy
22
+
23
+ Then use it!
24
+
25
+ require 'addy'
26
+
27
+ class MyClass
28
+ #include it in a class or in Object to get it everywhere
29
+ include Addy
30
+
31
+ def my_awesome_adder(range)
32
+ sum(range)
33
+ end
34
+ end
35
+
36
+ ### Calling It
37
+ You can call either sum or summation. They're aliases for the same thing.
38
+
39
+ When you pass a block to sum it will execute the block on the current number before adding it to the sum.
40
+
41
+ sum(1..5) {|num| num + 1} #=> 20
42
+
43
+ You don't have to pass a block though!
44
+
45
+ #this
46
+ sum(1..5) #=> 15
47
+
48
+ #is equivalent to
49
+ sum(1..5) {|num| num} #=> 15
50
+ ### Input
51
+ Ranges and numeric arrays both work well.
52
+
53
+ sum(1..5) #=> 15
54
+ sum([1,2,3,4,5]) #=> 15
55
+
56
+
57
+
58
+ ## Note on Patches/Pull Requests
59
+
60
+ * Fork the project.
61
+ * Make your feature addition or bug fix.
62
+ * Add tests for it. This is important so I don't break it in a
63
+ future version unintentionally.
64
+ * Commit, do not mess with rakefile, version, or history.
65
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
66
+ * Send me a pull request. Bonus points for topic branches.
67
+
68
+ ## Copyright
69
+
70
+ Copyright (c) 2010 Allen Madsen. See LICENSE for details.
71
+
72
+ ## PS: Isn't it ridiculous how much documentation I wrote for one function?
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "addy"
8
+ gem.summary = %Q{Prettier summations in your code.}
9
+ gem.description = %Q{Prettier summations in your code.}
10
+ gem.email = "blatyo@gmail.com"
11
+ gem.homepage = "http://github.com/blatyo/addy"
12
+ gem.authors = ["Allen Madsen"]
13
+ gem.add_development_dependency "rspec", ">= 1.3.0"
14
+ gem.add_development_dependency "yard", ">= 0"
15
+ gem.add_development_dependency "cucumber", ">= 0"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ begin
38
+ require 'cucumber/rake/task'
39
+ Cucumber::Rake::Task.new(:features)
40
+
41
+ task :features => :check_dependencies
42
+ rescue LoadError
43
+ task :features do
44
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
45
+ end
46
+ end
47
+
48
+ task :default => :spec
49
+
50
+ begin
51
+ require 'yard'
52
+ YARD::Rake::YardocTask.new
53
+ rescue LoadError
54
+ task :yardoc do
55
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
56
+ end
57
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'addy'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,13 @@
1
+ module Addy
2
+ def summation(range)
3
+ range.inject(0) do |memo, num|
4
+ if block_given?
5
+ yield(num) + memo
6
+ else
7
+ num + memo
8
+ end
9
+ end
10
+ end
11
+
12
+ alias :sum :summation
13
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Addy do
4
+ before(:all) do
5
+ class ::Object
6
+ include ::Addy
7
+ end
8
+ end
9
+
10
+ describe "#sum" do
11
+ context "when no block is given" do
12
+ it "should calculate the sum of the values in the range" do
13
+ sum(1..5).should == 15
14
+ end
15
+ end
16
+
17
+ context "when a block is given" do
18
+ it "should calculate the sum of the results of the block for each value in the range" do
19
+ sum(1..3) {|i| i**i }.should == 32
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'addy'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: addy
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Allen Madsen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-19 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 3
31
+ - 0
32
+ version: 1.3.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: yard
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: cucumber
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 0
58
+ version: "0"
59
+ type: :development
60
+ version_requirements: *id003
61
+ description: Prettier summations in your code.
62
+ email: blatyo@gmail.com
63
+ executables: []
64
+
65
+ extensions: []
66
+
67
+ extra_rdoc_files:
68
+ - LICENSE.md
69
+ - README.md
70
+ files:
71
+ - .document
72
+ - .gitignore
73
+ - .rvmrc
74
+ - Gemfile
75
+ - LICENSE.md
76
+ - README.md
77
+ - Rakefile
78
+ - VERSION
79
+ - features/addy.feature
80
+ - features/step_definitions/addy_steps.rb
81
+ - features/support/env.rb
82
+ - lib/addy.rb
83
+ - spec/addy_spec.rb
84
+ - spec/spec.opts
85
+ - spec/spec_helper.rb
86
+ has_rdoc: true
87
+ homepage: http://github.com/blatyo/addy
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options:
92
+ - --charset=UTF-8
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project:
114
+ rubygems_version: 1.3.7
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: Prettier summations in your code.
118
+ test_files:
119
+ - spec/addy_spec.rb
120
+ - spec/spec_helper.rb