linesman 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/Gemfile +7 -0
- data/HISTORY.md +1 -0
- data/LICENSE +20 -0
- data/README.md +61 -0
- data/Rakefile +7 -0
- data/lib/linesman/version.rb +3 -0
- data/lib/linesman.rb +28 -0
- data/linesman.gemspec +23 -0
- data/spec/linesman_spec.rb +76 -0
- data/spec/spec_helper.rb +12 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDU1OTQ0OGQzYTM0ZWVjYjVlYzkzYTU5MTYwMDM0ZmQ5ODg0Y2E3MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTEyNzFmZWQ2MjVjMDA0OWI5NTFmNzlkMTc4MzM3NDI5OTZiMDA5Mg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MTEyNGE3NGVkZTkzZjA1OTU5ODUwMzgyZWUxZjI3OTUwMTAyMGIxYjZmNjE5
|
10
|
+
MzFiOTA5MDc1YTE0ZGY4MzcxMGQyMWU5Mzk1MTYwNjVmY2E3NmRjY2MzZjA1
|
11
|
+
MTExNTI0Nzk0NmJhMWEwYjMyNmUyNmQxNzgxNDRlYzIyNDM0YWU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NmExNDE1OTViZWI3YTc1YWViZDk3NjI5NmY1MWUwMzRkN2RjZWNlZjVjZWIw
|
14
|
+
NGI5NTMxZTJlMzBjNDQ5OTE3MzJkZDcwOTdkOGM1YjVkZmRiYjE0ZDcyNTNl
|
15
|
+
MjkyZTY3YjZhMzEyZTdjYjExNDE0NmI5MDM3YjliOGI5YjcyYTg=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/HISTORY.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
* 0.0.1 - Initial Release
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Dennis Walters
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
## Linesman ##
|
2
|
+
|
3
|
+
Determine if a value is in-bounds
|
4
|
+
|
5
|
+
## Gem Setup ##
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem install linesman
|
9
|
+
|
10
|
+
# Gemfile
|
11
|
+
gem 'linesman'
|
12
|
+
```
|
13
|
+
## How Do I Use This Thing? ##
|
14
|
+
|
15
|
+
There's not really much to it. There is only one method: Linesman.within_bounds?
|
16
|
+
|
17
|
+
It takes an option hash and a block.
|
18
|
+
|
19
|
+
The options hash must contain at least one of the following:
|
20
|
+
|
21
|
+
* :exactly
|
22
|
+
* :min
|
23
|
+
* :max
|
24
|
+
|
25
|
+
The block should return a value that is comparable to the bounds specified in
|
26
|
+
the options hash.
|
27
|
+
|
28
|
+
The method returns either true or false based on the given criteria.
|
29
|
+
|
30
|
+
Examples:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Linesman.within_bounds?(exactly: 1) {2 - 1} # => true
|
34
|
+
|
35
|
+
Linesman.within_bounds?(min: 1, max: 10) {1} # => true
|
36
|
+
Linesman.within_bounds?(min: 1) {0} # => false
|
37
|
+
Linesman.within_bounds?(max: 1) {0} # => true
|
38
|
+
```
|
39
|
+
|
40
|
+
## Formal Documentation ##
|
41
|
+
|
42
|
+
The actual library docs can be read
|
43
|
+
[over on rubydoc](http://rubydoc.info/gems/linesman/frames).
|
44
|
+
|
45
|
+
## Contributing ##
|
46
|
+
|
47
|
+
Do you use git-flow? I sure do. Please base anything you do off of
|
48
|
+
[the develop branch](https://github.com/ess/linesman/tree/develop).
|
49
|
+
|
50
|
+
1. Fork it.
|
51
|
+
2. Perform some BDD magic. Seriously. Be testing.
|
52
|
+
3. Submit a pull request.
|
53
|
+
|
54
|
+
## So, Uh, Why? ##
|
55
|
+
|
56
|
+
In short, I've been needing this exact functionality all over the place of
|
57
|
+
late, and it was quick enough to just throw it together.
|
58
|
+
|
59
|
+
## License ##
|
60
|
+
|
61
|
+
MIT License. Copyright 2013 Ess
|
data/Rakefile
ADDED
data/lib/linesman.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'linesman/version'
|
2
|
+
|
3
|
+
module Linesman
|
4
|
+
def self.within_bounds?(options = {}, &block)
|
5
|
+
at_least_one = [:exactly, :min, :max]
|
6
|
+
unless at_least_one.map {|key| options.has_key?(key)}.any? {|present| present}
|
7
|
+
raise ArgumentError.new('At least one of the following is required: :exactly, :min, :max')
|
8
|
+
end
|
9
|
+
|
10
|
+
raise ArgumentError.new('a block is required') if block.nil?
|
11
|
+
|
12
|
+
exactly = options[:exactly]
|
13
|
+
min = options[:min]
|
14
|
+
max = options[:max]
|
15
|
+
|
16
|
+
under_scrutiny = block.call
|
17
|
+
|
18
|
+
if exactly
|
19
|
+
return under_scrutiny == exactly
|
20
|
+
elsif min && max
|
21
|
+
return under_scrutiny >= min && under_scrutiny <= max
|
22
|
+
elsif min
|
23
|
+
return under_scrutiny >= min
|
24
|
+
else
|
25
|
+
return under_scrutiny <= max
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/linesman.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/linesman/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Dennis Walters"]
|
6
|
+
gem.email = ["dennis@elevatorup.com"]
|
7
|
+
gem.summary = %q{Determines if values are in bounds}
|
8
|
+
gem.description = <<-EOD
|
9
|
+
Linesman is a simple module that helps one determine if a
|
10
|
+
value is within a given set of bounds.
|
11
|
+
EOD
|
12
|
+
gem.homepage = "http://github.com/ess/linesman"
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.name = "linesman"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = Linesman::VERSION
|
21
|
+
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'linesman'
|
3
|
+
|
4
|
+
describe Linesman do
|
5
|
+
let(:klass) {Linesman}
|
6
|
+
|
7
|
+
describe '.within_bounds?' do
|
8
|
+
it 'requires :exactly or some combination of :min and :max' do
|
9
|
+
expect {klass.within_bounds?() {}}.to raise_error(ArgumentError)
|
10
|
+
expect {klass.within_bounds?(exactly: 1) {1}}.not_to raise_error
|
11
|
+
expect {klass.within_bounds?(min: 1) {1}}.not_to raise_error
|
12
|
+
expect {klass.within_bounds?(max: 1) {1}}.not_to raise_error
|
13
|
+
expect {klass.within_bounds?(exactly: 1, min: 1, max: 1) {1}}.not_to raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'requires a block' do
|
17
|
+
expect {klass.within_bounds?(exactly: 1)}.to raise_error(ArgumentError)
|
18
|
+
expect {klass.within_bounds?(exactly: 1) {0}}.not_to raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with :exactly specified' do
|
22
|
+
it 'ignores :min and :max' do
|
23
|
+
expect(klass.within_bounds?(exactly: 1, min: 2) {1}).to be_true
|
24
|
+
expect(klass.within_bounds?(exactly: 1, max: 0) {1}).to be_true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'is true if the block value is exactly as specified' do
|
28
|
+
expect(klass.within_bounds?(exactly: 1) {1}).to be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'is false if the block value is not exactly as specified' do
|
32
|
+
expect(klass.within_bounds?(exactly: 1) {0}).to be_false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'with :min specified' do
|
37
|
+
it 'is true if the block value is at least as specified' do
|
38
|
+
expect(klass.within_bounds?(min: 1) {1}).to be_true
|
39
|
+
expect(klass.within_bounds?(min: 1) {2}).to be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'is false if the block value is less than as specified' do
|
43
|
+
expect(klass.within_bounds?(min: 1) {0}).to be_false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'with :max specified' do
|
48
|
+
it 'is true if the block value is at most as specified' do
|
49
|
+
expect(klass.within_bounds?(max: 10) {10}).to be_true
|
50
|
+
expect(klass.within_bounds?(max: 10) {9}).to be_true
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'is false if the block value is more than as specified' do
|
54
|
+
expect(klass.within_bounds?(max: 10) {11}).to be_false
|
55
|
+
expect(klass.within_bounds?(max: 10) {100}).to be_false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with :min and :max specified' do
|
60
|
+
it 'is true if the block value is within the inclusive range min..max' do
|
61
|
+
min = 1
|
62
|
+
max = 10
|
63
|
+
(min..max).each do |value|
|
64
|
+
expect(klass.within_bounds?(min: min, max: max) {value}).to be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'is false if the block value is outside the inclusive range min..max' do
|
69
|
+
min = 10
|
70
|
+
max = 20
|
71
|
+
expect(klass.within_bounds?(min: min, max: max) {min - 1}).to be_false
|
72
|
+
expect(klass.within_bounds?(min: min, max: max) {max + 1}).to be_false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: linesman
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Walters
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
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
|
+
description: ! " Linesman is a simple module that helps one determine if a\n value
|
28
|
+
is within a given set of bounds.\n"
|
29
|
+
email:
|
30
|
+
- dennis@elevatorup.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- HISTORY.md
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/linesman.rb
|
42
|
+
- lib/linesman/version.rb
|
43
|
+
- linesman.gemspec
|
44
|
+
- spec/linesman_spec.rb
|
45
|
+
- spec/spec_helper.rb
|
46
|
+
homepage: http://github.com/ess/linesman
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.1.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Determines if values are in bounds
|
70
|
+
test_files:
|
71
|
+
- spec/linesman_spec.rb
|
72
|
+
- spec/spec_helper.rb
|