limit_detectors 0.0.2

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: 78527c872487245d652a43920f4d3c092fcb01a2
4
+ data.tar.gz: 5176b76ac3e59ac4ff1c6ff18e2712accc118018
5
+ SHA512:
6
+ metadata.gz: a4bb6f07cbb425ff35eea70adf812e1c928099a92f0022f17c3945cfba7b0a7ed5bb2b8f833c08c58a12853751d9d5f8f7c6a3443b374da0457d3dbb2b3e0c74
7
+ data.tar.gz: ee6eba30bf7560e9d0f88c121b53f59ead1ad5f6c23e9dbbb485c8643e25fbdce350b5466afadf2534d1ed982b0ab5218c7e4cd6126b6f6682c49f05514badbf
data/.gitignore ADDED
@@ -0,0 +1,26 @@
1
+ *.bundle
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ /.yardoc/
8
+ /_yardoc/
9
+ /doc/
10
+ /lib/bundler/man/
11
+ /rdoc/
12
+ _yardoc
13
+ coverage
14
+ doc/
15
+ Gemfile.lock
16
+ InstalledFiles
17
+ lib/bundler/man
18
+ mkmf.log
19
+ pkg
20
+ rdoc
21
+ spec/reports
22
+ test/tmp
23
+ test/version_tmp
24
+ tmp
25
+
26
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "1.8.7"
5
+ - "2.0"
6
+ - "2.1"
7
+ - "2.1.1"
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in limit_detectors.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Stephan Kämper
2
+
3
+ MIT License
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,75 @@
1
+ # LimitDetectors
2
+
3
+ Some methods to detect whether an Enumberable object contains a constrained number of elements that match a given condition
4
+
5
+ ## Stati
6
+
7
+ * Travis CI: [![Build Status](https://travis-ci.org/s2k/limit_detectors.svg?branch=master)](https://travis-ci.org/s2k/limit_detectors)
8
+ * Maintenance: [![Project Status](http://stillmaintained.com/s2k/limit_detectors.png)](http://stillmaintained.com/s2k/limit_detectors)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'limit_detectors'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install limit_detectors
23
+
24
+ ## Usage
25
+
26
+ In your code you can `require 'limit_detectors'` then define you classes (or use built-in classes like Array, Hash
27
+ or other enumerable objects), extend these objects with LimitDetectors (or include the module in your class) and
28
+ then call `at_most` on your object.
29
+
30
+ For example:
31
+
32
+ $pry -I lib -r limit_detectors
33
+ [1] pry(main)> a = [1, 2, 3, 4, 5]
34
+ => [1, 2, 3, 4, 5]
35
+ [2] pry(main)> a.extend LimitDetectors
36
+ => [1, 2, 3, 4, 5]
37
+ [3] pry(main)> a.at_most(4){|e| e.odd?}
38
+ => true # There are indeed no more than 4 odd numbers in the array
39
+ [4] pry(main)> a.at_most(1){|e| e.even?}
40
+ => false # In fact there are two even numbers in the array
41
+
42
+ ## Compatibility
43
+
44
+ Please note the current version of 0.0.something, which means the future releases
45
+ may not be compatible with the current version.
46
+
47
+ This gem is tested with these (MRI) Ruby versions:
48
+
49
+ * 1.8.7
50
+ * 1.9.3
51
+ * 2.0
52
+ * 2.1
53
+ * 2.1.1
54
+
55
+
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it ( https://github.com/[my-github-username]/limit_detectors/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
64
+
65
+ ### Reporting a bug
66
+
67
+ Please, provide answers to the following questions, when submitting a bug report:
68
+
69
+ 1. What's actually happening? What the observed behaviour?
70
+ 2. What's the expectation, i.e. what should have happened?
71
+ 3. Why did you expect this behaviour?
72
+
73
+ If you provide an RSpec check that demonstrates the bug, would give extra good karma,
74
+ especially in case of a minimal check, something that just demonstrates the bug without
75
+ any (or much) overhead.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new :spec
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ exec 'irb -I ./lib -r limit_detectors'
10
+ end
@@ -0,0 +1,3 @@
1
+ module LimitDetectors
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,12 @@
1
+ require 'limit_detectors/version'
2
+
3
+ module LimitDetectors
4
+ def at_most(limit)
5
+
6
+ count = inject(0){ |res, el|
7
+ res += 1 if yield el
8
+ res
9
+ }
10
+ count <= limit
11
+ end
12
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'limit_detectors/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'limit_detectors'
8
+ spec.version = LimitDetectors::VERSION
9
+ spec.authors = ['Stephan Kämper']
10
+ spec.email = ['the.tester@seasidetesting.com']
11
+ spec.summary = %q{Detect certain conditions of elements of an Enumerable object}
12
+ spec.description = %q{Some methods to detect whether an Enumerable object contains a constrained number of elements that match a given condition.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'pry-doc'
26
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe 'Array#at_most' do
5
+ Array.send :include, LimitDetectors
6
+
7
+ it 'is true for an empty Array' do
8
+ expect([].at_most(5){ true }).to be_true
9
+ end
10
+
11
+ it 'is true if the criterion is met once' do
12
+ expect(["it's there"].at_most(1){ |el| el == "it's there"}).to be_true
13
+ end
14
+
15
+ it 'is true if all elements meet the criterion and the size is the given maximum number' do
16
+ expect([1,1,1].at_most(3){|e| e == 1})
17
+ end
18
+
19
+ it 'is false if not enough elements meet the criterion' do
20
+ expect([1, 2, 4].at_most(1){|e| e.even?}).to be_false
21
+ end
22
+
23
+ it 'is true if 0 elements are expected to match' do
24
+ r = Array.new(10){rand}
25
+ expect(r.at_most(0){ |i| i > 2 }).to be_true
26
+ end
27
+
28
+ end
29
+
30
+
31
+ describe 'Hash#at_most' do
32
+ Hash.send :include, LimitDetectors
33
+ it 'detects a condition based on key as well as value properties' do
34
+ h = { 'foo' => 1, 'bar' => 4, 'baz' => 5, 'bum' => 1, 'fum' => 0}
35
+ expect( h.at_most(3){|ky,vl| ky.match(/^b/) || vl > 1 }).to be_true
36
+ end
37
+ end
38
+
39
+
40
+ describe 'Using an object that doesn\'t respond to #inject will raise an exception' do
41
+ object = Object.new
42
+ object.extend LimitDetectors
43
+ it 'will raise an exception, if it\'s sent #atmost' do
44
+ expect{ object.at_most(1){ |el| el.condition? } }.to raise_exception(NoMethodError, /undefined method .inject./)
45
+ end
46
+ end
@@ -0,0 +1,19 @@
1
+ require 'limit_detectors'
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # Require this file using `require "spec_helper"` to ensure that it is only
6
+ # loaded once.
7
+ #
8
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
9
+ RSpec.configure do |config|
10
+ #config.treat_symbols_as_metadata_keys_with_true_values = true
11
+ #config.run_all_when_everything_filtered = true
12
+ #config.filter_run :focus
13
+
14
+ # Run specs in random order to surface order dependencies. If you find an
15
+ # order dependency and want to debug it, you can fix the order by providing
16
+ # the seed, which is printed after each run.
17
+ # --seed 1234
18
+ config.order = 'random'
19
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: limit_detectors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Stephan Kämper
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-20 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-doc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Some methods to detect whether an Enumerable object contains a constrained
84
+ number of elements that match a given condition.
85
+ email:
86
+ - the.tester@seasidetesting.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/limit_detectors.rb
99
+ - lib/limit_detectors/version.rb
100
+ - limit_detectors.gemspec
101
+ - spec/limit_detectors_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: ''
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.2.2
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Detect certain conditions of elements of an Enumerable object
127
+ test_files:
128
+ - spec/limit_detectors_spec.rb
129
+ - spec/spec_helper.rb
130
+ has_rdoc: