bools 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. checksums.yaml +7 -0
  2. data/.ruby-version +1 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +21 -0
  5. data/README.md +48 -0
  6. data/bools.gemspec +13 -0
  7. data/lib/bools.rb +15 -0
  8. metadata +49 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 18bb7c86f9e8d827350e3a5eca69da9bf8178693a11b04f09dea813210652ca3
4
+ data.tar.gz: dcbfc9eec87c102073c9d50867d61f23800bff32a24802ced02ff0de37941f58
5
+ SHA512:
6
+ metadata.gz: 2c0336d44e61cae6e0585dba03d4e887f3971c33827e54d986f86f11873322193f436c4b56eeae2c29564d8cf6513a5f9166cbdb6491c231567b165af02b7da6
7
+ data.tar.gz: 515c8ba0a643ea29f3272aae08e94ba426114631720bdf824901056a175615977080df709eb0c1f8381ec0413e281c15a994f71bc8a787658b94f93d28c78b32
@@ -0,0 +1 @@
1
+ 2.5
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Steve Shreeve
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # bools
2
+
3
+ `bools` is a small Ruby gem that makes it easy to evaluate boolean conditionals.
4
+
5
+ ## Howto
6
+
7
+ Just `require 'bools'` and write a method called `test` that accepts one or
8
+ more boolean values. Process those values and return a boolean. A table will
9
+ be output which shows all the possible input values and their results. The
10
+ total number of combinations of input variables will be dynamically calculated
11
+ based on the arity of the `test` method.
12
+
13
+ ## Examples
14
+
15
+ This small file:
16
+
17
+ ```ruby
18
+ require 'bools'
19
+
20
+ def test(a, b, c, d)
21
+ a == c
22
+ end
23
+ ```
24
+
25
+ Produces the following:
26
+
27
+ ```
28
+ a b c d | result
29
+ --------+-------
30
+ 0 0 0 0 | 1
31
+ 0 0 0 1 | 1
32
+ 0 0 1 0 | 0
33
+ 0 0 1 1 | 0
34
+ 0 1 0 0 | 1
35
+ 0 1 0 1 | 1
36
+ 0 1 1 0 | 0
37
+ 0 1 1 1 | 0
38
+ ```
39
+
40
+ Notice that 4 booleans are checked, since there are 4 input variables.
41
+
42
+ ## Why?
43
+
44
+ Many times when coding, it is necessary to process multiple conditionals in
45
+ order to return a desired result. This can get pretty tedious when trying to
46
+ calculate all combinations by hand. This library allows you to define a single
47
+ method, called `test`, supply however many input booleans you need, define the
48
+ logic that returns the final result, and display everything in a small table.
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "bools"
5
+ s.version = "0.5.0"
6
+ s.author = "Steve Shreeve"
7
+ s.email = "steve.shreeve@gmail.com"
8
+ s.summary = "Bools is a Ruby gem that makes it easy to evaluate boolean conditionals"
9
+ s.description = "Write one method and bools will test all input combinations"
10
+ s.homepage = "https://github.com/shreeve/bools"
11
+ s.license = "MIT"
12
+ s.files = `git ls-files`.split("\n") - %w[.gitignore]
13
+ end
@@ -0,0 +1,15 @@
1
+ def bools!
2
+ vars = method(:test).arity
3
+ list = vars.times.map {|i| (97 + i).chr}
4
+ puts
5
+ puts [*list, '|', 'result'] * ' '
6
+ puts ['--' * list.size, '-' * 6] * '+-'
7
+ (vars << 1).times do |i|
8
+ list = ("%0*b" % [vars, i]).split('')
9
+ vals = list.map {|item| item == '1'}
10
+ resu = !!test(*vals) ? '1' : '0'
11
+ puts [*list, '|', resu] * ' '
12
+ end
13
+ end
14
+
15
+ at_exit { bools! }
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Steve Shreeve
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Write one method and bools will test all input combinations
14
+ email: steve.shreeve@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".ruby-version"
20
+ - Gemfile
21
+ - LICENSE
22
+ - README.md
23
+ - bools.gemspec
24
+ - lib/bools.rb
25
+ homepage: https://github.com/shreeve/bools
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.7.7
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: Bools is a Ruby gem that makes it easy to evaluate boolean conditionals
49
+ test_files: []