visfleet-ternary_logic 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +37 -0
- data/Rakefile +48 -0
- data/VERSION +1 -0
- data/lib/ternary_logic.rb +29 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/ternary_logic_spec.rb +33 -0
- data/ternary_logic.gemspec +47 -0
- metadata +64 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 VisFleet
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
= ternary_logic
|
2
|
+
|
3
|
+
This library implements Ternary Logic for Ruby. Ternary logic (also known as 3-value-logic) adds the value "Unknown" to the two traditional (i.e. boolean) logic values, True and False. This is useful for adding a bit of fuzzyness into your logic.
|
4
|
+
|
5
|
+
To install:
|
6
|
+
|
7
|
+
sudo gem install visfleet-ternary_logic
|
8
|
+
|
9
|
+
To use:
|
10
|
+
|
11
|
+
require 'ternary_logic'
|
12
|
+
|
13
|
+
You now have the additional constant, UNKNOWN, to use alongside the constants true and false.
|
14
|
+
|
15
|
+
state = UNKNOWN
|
16
|
+
if state == UNKNWON
|
17
|
+
puts "Don't know?"
|
18
|
+
end
|
19
|
+
|
20
|
+
You can use the logical operators "|" and "&" to compare UNKNOWN with true and false values.
|
21
|
+
|
22
|
+
state = (true | UNKNOWN)
|
23
|
+
state = (UNKNOWN & true)
|
24
|
+
|
25
|
+
Ternary logic uses the following truth table:
|
26
|
+
|
27
|
+
UNKNOWN & true == UNKNOWN
|
28
|
+
UNKNOWN & false == false
|
29
|
+
UNKNOWN & UNKNOWN == UNKNOWN
|
30
|
+
|
31
|
+
UNKNOWN | true == true
|
32
|
+
UNKNOWN | false == UNKNOWN
|
33
|
+
UNKNOWN | UNKNOWN == UNKNOWN
|
34
|
+
|
35
|
+
== Copyright
|
36
|
+
|
37
|
+
Copyright (c) 2009 VisFleet. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ternary_logic"
|
8
|
+
gem.summary = %Q{TODO}
|
9
|
+
gem.email = "aisha.fenton@visfleet.com"
|
10
|
+
gem.homepage = "http://github.com/visfleet/ternary_logic"
|
11
|
+
gem.authors = ["Aisha Fenton"]
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/spectask'
|
20
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
21
|
+
spec.libs << 'lib' << 'spec'
|
22
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
23
|
+
end
|
24
|
+
|
25
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
26
|
+
spec.libs << 'lib' << 'spec'
|
27
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
28
|
+
spec.rcov = true
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task :default => :spec
|
33
|
+
|
34
|
+
require 'rake/rdoctask'
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
if File.exist?('VERSION.yml')
|
37
|
+
config = YAML.load(File.read('VERSION.yml'))
|
38
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
39
|
+
else
|
40
|
+
version = ""
|
41
|
+
end
|
42
|
+
|
43
|
+
rdoc.rdoc_dir = 'rdoc'
|
44
|
+
rdoc.title = "ternary_logic #{version}"
|
45
|
+
rdoc.rdoc_files.include('README*')
|
46
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
47
|
+
end
|
48
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# The third state: true, false and UNKNOWN.
|
2
|
+
#
|
3
|
+
class UnknownValue
|
4
|
+
def |(value)
|
5
|
+
value == true ? true : self
|
6
|
+
end
|
7
|
+
|
8
|
+
def &(value)
|
9
|
+
value == false ? false : self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
UNKNOWN = UnknownValue.new
|
14
|
+
|
15
|
+
class <<false
|
16
|
+
def new_or(value)
|
17
|
+
(value == UNKNOWN) ? UNKNOWN : self.old_or(value)
|
18
|
+
end
|
19
|
+
alias_method :old_or, :|
|
20
|
+
alias_method :|, :new_or
|
21
|
+
end
|
22
|
+
|
23
|
+
class <<true
|
24
|
+
def new_and(value)
|
25
|
+
(value == UNKNOWN) ? UNKNOWN : self.old_and(value)
|
26
|
+
end
|
27
|
+
alias_method :old_and, :&
|
28
|
+
alias_method :&, :new_and
|
29
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
describe "TernaryLogic" do
|
5
|
+
it "should provide 3-valued-logic for the OR operator" do
|
6
|
+
(UNKNOWN | false).should == UNKNOWN
|
7
|
+
(UNKNOWN | true).should == true
|
8
|
+
(true | UNKNOWN).should == true
|
9
|
+
(false | UNKNOWN).should == UNKNOWN
|
10
|
+
(UNKNOWN | UNKNOWN).should == UNKNOWN
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should provide 3-valued-logic for the AND operator" do
|
14
|
+
(UNKNOWN & false).should == false
|
15
|
+
(UNKNOWN & true).should == UNKNOWN
|
16
|
+
(true & UNKNOWN).should == UNKNOWN
|
17
|
+
(false & UNKNOWN).should == false
|
18
|
+
(UNKNOWN & UNKNOWN).should == UNKNOWN
|
19
|
+
end
|
20
|
+
|
21
|
+
it "shoudn't break the existing | or & methods" do
|
22
|
+
(true & true).should == true
|
23
|
+
(true & false).should == false
|
24
|
+
(false & true).should == false
|
25
|
+
(false & false).should == false
|
26
|
+
|
27
|
+
(true | true).should == true
|
28
|
+
(true | false).should == true
|
29
|
+
(false | true).should == true
|
30
|
+
(false | false).should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{ternary_logic}
|
5
|
+
s.version = "1.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Aisha Fenton"]
|
9
|
+
s.date = %q{2009-05-24}
|
10
|
+
s.email = %q{aisha.fenton@visfleet.com}
|
11
|
+
s.extra_rdoc_files = [
|
12
|
+
"LICENSE",
|
13
|
+
"README.rdoc"
|
14
|
+
]
|
15
|
+
s.files = [
|
16
|
+
".document",
|
17
|
+
".gitignore",
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION",
|
22
|
+
"lib/ternary_logic.rb",
|
23
|
+
"spec/spec_helper.rb",
|
24
|
+
"spec/ternary_logic_spec.rb",
|
25
|
+
"ternary_logic.gemspec"
|
26
|
+
]
|
27
|
+
s.has_rdoc = true
|
28
|
+
s.homepage = %q{http://github.com/visfleet/ternary_logic}
|
29
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
30
|
+
s.require_paths = ["lib"]
|
31
|
+
s.rubygems_version = %q{1.3.1}
|
32
|
+
s.summary = %q{TODO}
|
33
|
+
s.test_files = [
|
34
|
+
"spec/spec_helper.rb",
|
35
|
+
"spec/ternary_logic_spec.rb"
|
36
|
+
]
|
37
|
+
|
38
|
+
if s.respond_to? :specification_version then
|
39
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
40
|
+
s.specification_version = 2
|
41
|
+
|
42
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
43
|
+
else
|
44
|
+
end
|
45
|
+
else
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visfleet-ternary_logic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aisha Fenton
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: aisha.fenton@visfleet.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
- Rakefile
|
31
|
+
- VERSION
|
32
|
+
- lib/ternary_logic.rb
|
33
|
+
- spec/spec_helper.rb
|
34
|
+
- spec/ternary_logic_spec.rb
|
35
|
+
- ternary_logic.gemspec
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/visfleet/ternary_logic
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.2.0
|
59
|
+
signing_key:
|
60
|
+
specification_version: 2
|
61
|
+
summary: TODO
|
62
|
+
test_files:
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
- spec/ternary_logic_spec.rb
|