enumerable-detect-value 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +26 -0
- data/LICENSE.md +22 -0
- data/README.md +41 -0
- data/Rakefile +13 -0
- data/enumerable-detect-value.gemspec +15 -0
- data/lib/enumerable-detect-value.rb +10 -0
- data/lib/enumerable_detect_value.rb +2 -0
- data/spec/array_spec.rb +21 -0
- data/spec/spec_helper.rb +6 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2224df91f783ac55ec64d4109228d6d4733959a7
|
4
|
+
data.tar.gz: 87bb85584f63e6b01aa1e6c9f11c1f535b2d6a7f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 80cb61baea5f104b7d258280fb0e317128e0cd1c53fcc569c768f6df0dc5053a56352726ba5b0eecd37dbe6a7457c14f36d5be28c245c8955606677387f51bcc
|
7
|
+
data.tar.gz: dd68f6da31e423c92bb7b5ea2b1e86a7aa704220896e97bdd66b469ecf4a4354650306438a62c46260478705265875630559300b78b9b8ee50df0467d3946ef5
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
enumerable-detect-value (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
rake (10.1.1)
|
11
|
+
rspec (2.14.1)
|
12
|
+
rspec-core (~> 2.14.0)
|
13
|
+
rspec-expectations (~> 2.14.0)
|
14
|
+
rspec-mocks (~> 2.14.0)
|
15
|
+
rspec-core (2.14.7)
|
16
|
+
rspec-expectations (2.14.4)
|
17
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
18
|
+
rspec-mocks (2.14.4)
|
19
|
+
|
20
|
+
PLATFORMS
|
21
|
+
ruby
|
22
|
+
|
23
|
+
DEPENDENCIES
|
24
|
+
enumerable-detect-value!
|
25
|
+
rake
|
26
|
+
rspec
|
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2013 Daniel Doubrovkine.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
Array Detect w/ Value
|
2
|
+
=====================
|
3
|
+
|
4
|
+
[![Build Status](https://travis-ci.org/dblock/array-detect-value.png)](https://travis-ci.org/dblock/array-detect-value)
|
5
|
+
|
6
|
+
## Detect Value
|
7
|
+
|
8
|
+
Unlike `Enumerable#detect`, `#detect_value` returns the result of the block being evaluated.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
ary = [ nil, 2, 3 ]
|
12
|
+
|
13
|
+
# returns 2, the first element for which the block evaluated to a non-nil result
|
14
|
+
ary.detect do |value|
|
15
|
+
value ? value * 10 : nil
|
16
|
+
end
|
17
|
+
|
18
|
+
# returns 20, the first non-nil result of the block being evaluated
|
19
|
+
ary.detect_value do |value|
|
20
|
+
value ? value * 10 : nil
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
|
26
|
+
You're encouraged to contribute to this gem.
|
27
|
+
|
28
|
+
* Fork this project.
|
29
|
+
* Create a feature branch with `git checkout -b my-branch`.
|
30
|
+
* Make changes, write tests, ensure that `rake` runs clean.
|
31
|
+
* Commit your changes with `git commit`.
|
32
|
+
* Push your branch to Github with `git push origin my-branch`.
|
33
|
+
* Make a pull request, note the number.
|
34
|
+
* Updated [CHANGELOG](CHANGELOG.md) and commit via `git --amend`.
|
35
|
+
* Push an update via `git push origin my-branch -f`.
|
36
|
+
|
37
|
+
## Copyright and License
|
38
|
+
|
39
|
+
Copyright (c) 2013, Daniel Doubrovkine.
|
40
|
+
|
41
|
+
This project is licensed under the [MIT License](LICENSE.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
Bundler.setup :default, :development
|
5
|
+
|
6
|
+
require 'rspec/core'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
10
|
+
spec.pattern = FileList["spec/**/*_spec.rb"]
|
11
|
+
end
|
12
|
+
|
13
|
+
task :default => :spec
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "enumerable-detect-value"
|
5
|
+
s.version = '0.1.0'
|
6
|
+
s.authors = [ "Daniel Doubrovkine" ]
|
7
|
+
s.email = "dblock@dblock.org"
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.required_rubygems_version = '>= 1.3.6'
|
10
|
+
s.files = Dir['**/*']
|
11
|
+
s.require_paths = [ "lib" ]
|
12
|
+
s.homepage = "http://github.com/dblock/enumerable-detect-value"
|
13
|
+
s.licenses = [ "MIT" ]
|
14
|
+
s.summary = "Unlike Enumerable#detect, #detect_value returns the evaluated value."
|
15
|
+
end
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe "#detect_value" do
|
5
|
+
it "does not evaluate after the first value" do
|
6
|
+
calls = 0
|
7
|
+
result = [ nil, 2, 3 ].detect_value do |value|
|
8
|
+
calls += 1
|
9
|
+
value ? value * 10 : nil
|
10
|
+
end
|
11
|
+
result.should == 20
|
12
|
+
calls.should == 2
|
13
|
+
end
|
14
|
+
it "returns nil" do
|
15
|
+
result = [ 1, 2, 3 ].detect_value do |value|
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
result.should be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enumerable-detect-value
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Doubrovkine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: dblock@dblock.org
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- CHANGELOG.md
|
20
|
+
- enumerable-detect-value.gemspec
|
21
|
+
- Gemfile
|
22
|
+
- Gemfile.lock
|
23
|
+
- lib/enumerable-detect-value.rb
|
24
|
+
- lib/enumerable_detect_value.rb
|
25
|
+
- LICENSE.md
|
26
|
+
- Rakefile
|
27
|
+
- README.md
|
28
|
+
- spec/array_spec.rb
|
29
|
+
- spec/spec_helper.rb
|
30
|
+
homepage: http://github.com/dblock/enumerable-detect-value
|
31
|
+
licenses:
|
32
|
+
- MIT
|
33
|
+
metadata: {}
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.6
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 2.1.11
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: 'Unlike Enumerable#detect, #detect_value returns the evaluated value.'
|
54
|
+
test_files: []
|