nutella 0.0.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.
- data/LICENSE +19 -0
- data/README.md +41 -0
- data/Rakefile +8 -0
- data/lib/nutella.rb +1 -0
- data/lib/nutella/core_ext.rb +3 -0
- data/lib/nutella/core_ext/enumerable.rb +21 -0
- data/lib/nutella/core_ext/string.rb +21 -0
- data/lib/nutella/version.rb +3 -0
- data/nutella.gemspec +25 -0
- data/spec/nutella/core_ext/enumerable_spec.rb +39 -0
- data/spec/nutella/core_ext/string_spec.rb +55 -0
- data/spec/spec_helper.rb +8 -0
- metadata +92 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2012 Vinny Diehl
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Nutella [](http://travis-ci.org/gbchaosmaster/nutella)
|
2
|
+
|
3
|
+
This library is my personal collection of Ruby utilities, mainly core
|
4
|
+
extensions. It is similar to
|
5
|
+
[Active Support](https://github.com/rails/rails/tree/master/activesupport),
|
6
|
+
but lighter.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Install with RubyGems:
|
11
|
+
|
12
|
+
```Shell
|
13
|
+
gem install nutella
|
14
|
+
```
|
15
|
+
|
16
|
+
## License
|
17
|
+
|
18
|
+
```nutella``` is released under the MIT license.
|
19
|
+
|
20
|
+
Copyright (C) 2012 Vinny Diehl
|
21
|
+
|
22
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
23
|
+
this software and associated documentation files (the "Software"), to deal in
|
24
|
+
the Software without restriction, including without limitation the rights to
|
25
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
26
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
27
|
+
so, subject to the following conditions:
|
28
|
+
|
29
|
+
The above copyright notice and this permission notice shall be included in all
|
30
|
+
copies or substantial portions of the Software.
|
31
|
+
|
32
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
33
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
34
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
35
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
36
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
37
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
38
|
+
SOFTWARE.
|
39
|
+
|
40
|
+
See [the official page on OSI](http://opensource.org/licenses/MIT) for more
|
41
|
+
information.
|
data/Rakefile
ADDED
data/lib/nutella.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "nutella/core_ext"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Enumerable
|
2
|
+
alias_method :contains?, :include?
|
3
|
+
alias_method :includes?, :include?
|
4
|
+
|
5
|
+
# The inverse of <tt>Enumerable#include?</tt>. Returns +true+ if the
|
6
|
+
# collection does not contain +object+.
|
7
|
+
def exclude? object
|
8
|
+
!include? object
|
9
|
+
end
|
10
|
+
alias_method :excludes?, :exclude?
|
11
|
+
|
12
|
+
# Returns the sum of all numeric elements in the collection
|
13
|
+
#
|
14
|
+
# [1, 2, 3].sum # => 6
|
15
|
+
# [[1, 2], [3, 4]].sum # => 10
|
16
|
+
# { a: 4, b: 5 }.sum # => 9
|
17
|
+
# [2, "string", 9].sum # => 11
|
18
|
+
def sum
|
19
|
+
flatten.select { |e| e.is_a? Numeric }.inject(:+) || 0
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class String
|
2
|
+
alias_method :contains?, :include?
|
3
|
+
alias_method :includes?, :include?
|
4
|
+
|
5
|
+
alias_method :each, :each_char
|
6
|
+
|
7
|
+
# The inverse of <tt>String#include?</tt>. Returns +true+ if the string does
|
8
|
+
# not contain +str+.
|
9
|
+
def exclude? str
|
10
|
+
!include? str
|
11
|
+
end
|
12
|
+
alias_method :excludes?, :exclude?
|
13
|
+
|
14
|
+
# Left-aligns a heredoc by finding the lest indented line in the string, and
|
15
|
+
# removing that amount of leading whitespace.
|
16
|
+
def heredoc
|
17
|
+
gsub /^[ \t]{#{scan(/^[ \t]*(?=\S)/).min.size}}/, ""
|
18
|
+
end
|
19
|
+
alias_method :format_heredoc, :heredoc
|
20
|
+
alias_method :strip_heredoc, :heredoc
|
21
|
+
end
|
data/nutella.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path("../lib/nutella/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "nutella"
|
5
|
+
gem.version = Nutella::VERSION
|
6
|
+
|
7
|
+
gem.author = "Vinny Diehl"
|
8
|
+
gem.email = "gbchaosmaster926@gmail.com"
|
9
|
+
gem.homepage = "https://github.com/gbchaosmaster/nutella"
|
10
|
+
|
11
|
+
gem.license = "MIT"
|
12
|
+
|
13
|
+
gem.summary = "Spread some Nutella on Ruby to sweeten up its functionality."
|
14
|
+
gem.description = "My collection of Ruby utilities, mainly core extensions."
|
15
|
+
|
16
|
+
gem.require_paths = %w[lib]
|
17
|
+
gem.test_files = Dir["spec/**/*"]
|
18
|
+
gem.files = Dir["lib/**/*"] + gem.test_files + %w[
|
19
|
+
LICENSE Rakefile README.md nutella.gemspec
|
20
|
+
]
|
21
|
+
|
22
|
+
gem.required_ruby_version = ">= 1.9.2"
|
23
|
+
gem.add_development_dependency "rake"
|
24
|
+
gem.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "nutella/core_ext/enumerable"
|
3
|
+
|
4
|
+
describe Enumerable do
|
5
|
+
describe "aliases" do
|
6
|
+
test_alias Enumerable, :contains?, :include?
|
7
|
+
test_alias Enumerable, :includes?, :include?
|
8
|
+
test_alias Enumerable, :excludes?, :exclude?
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#exclude?" do
|
12
|
+
it "should return true if the collection does not contain the input" do
|
13
|
+
[1, 2, 3].exclude?(4).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return false if the collection contains the input" do
|
17
|
+
[1, 2, 3].exclude?(2).should be_false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#sum" do
|
22
|
+
it "should return the sum of elements" do
|
23
|
+
[].sum.should == 0
|
24
|
+
[5].sum.should == 5
|
25
|
+
[1, 2, 3].sum.should == 6
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should flatten the elements before adding" do
|
29
|
+
[[4, 5], 1].sum.should == 10
|
30
|
+
[[1, 2, 3], [4, 5]].sum.should == 15
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should filter out all non-numbers" do
|
34
|
+
{ a: 2, b: 4 }.sum.should == 6
|
35
|
+
[1, "str", 4].sum.should == 5
|
36
|
+
["no numbers"].sum.should == 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "nutella/core_ext/string"
|
3
|
+
|
4
|
+
describe Enumerable do
|
5
|
+
describe "aliases" do
|
6
|
+
test_alias String, :contains?, :include?
|
7
|
+
test_alias String, :includes?, :include?
|
8
|
+
test_alias String, :excludes?, :exclude?
|
9
|
+
|
10
|
+
test_alias String, :each, :each_char
|
11
|
+
|
12
|
+
test_alias String, :format_heredoc, :heredoc
|
13
|
+
test_alias String, :strip_heredoc, :heredoc
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#exclude?" do
|
17
|
+
it "should return true if the string does not contain the input string" do
|
18
|
+
"hello".exclude?("test").should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return false if the string contains the input string" do
|
22
|
+
"hello".exclude?("llo").should be_false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#heredoc" do
|
27
|
+
test = expected = ""
|
28
|
+
|
29
|
+
before do
|
30
|
+
test = <<-EOS.heredoc
|
31
|
+
This is a test of String#heredoc.
|
32
|
+
This text should be left-aligned.
|
33
|
+
This text is indented by four spaces.
|
34
|
+
now three spaces...
|
35
|
+
now two spaces...
|
36
|
+
now one space...
|
37
|
+
Left-aligned again.
|
38
|
+
EOS
|
39
|
+
|
40
|
+
expected = <<EOS
|
41
|
+
This is a test of String#heredoc.
|
42
|
+
This text should be left-aligned.
|
43
|
+
This text is indented by four spaces.
|
44
|
+
now three spaces...
|
45
|
+
now two spaces...
|
46
|
+
now one space...
|
47
|
+
Left-aligned again.
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should strip all excess whitespace from the left" do
|
52
|
+
test.should == expected
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Tests if +method_a+ is an alias to +method_b+ in the class +cls+.
|
2
|
+
def test_alias(cls, method_a, method_b)
|
3
|
+
describe "##{method_a.to_s}" do
|
4
|
+
it "should be an alias of ##{method_b.to_s}" do
|
5
|
+
cls.instance_method(method_a).should === cls.instance_method(method_b)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nutella
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vinny Diehl
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: My collection of Ruby utilities, mainly core extensions.
|
47
|
+
email: gbchaosmaster926@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- lib/nutella.rb
|
53
|
+
- lib/nutella/version.rb
|
54
|
+
- lib/nutella/core_ext/string.rb
|
55
|
+
- lib/nutella/core_ext/enumerable.rb
|
56
|
+
- lib/nutella/core_ext.rb
|
57
|
+
- spec/nutella/core_ext/enumerable_spec.rb
|
58
|
+
- spec/nutella/core_ext/string_spec.rb
|
59
|
+
- spec/spec_helper.rb
|
60
|
+
- LICENSE
|
61
|
+
- Rakefile
|
62
|
+
- README.md
|
63
|
+
- nutella.gemspec
|
64
|
+
homepage: https://github.com/gbchaosmaster/nutella
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.9.2
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.24
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Spread some Nutella on Ruby to sweeten up its functionality.
|
89
|
+
test_files:
|
90
|
+
- spec/nutella/core_ext/enumerable_spec.rb
|
91
|
+
- spec/nutella/core_ext/string_spec.rb
|
92
|
+
- spec/spec_helper.rb
|