ternary_logic 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
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.
@@ -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.
@@ -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{Ternary logic support for Ruby, True, False, Unknown }
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
@@ -0,0 +1,9 @@
1
+ require 'spec'
2
+
3
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
5
+ require 'ternary_logic'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -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,50 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ternary_logic}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Aisha Fenton"]
12
+ s.date = %q{2010-09-22}
13
+ s.email = %q{aisha.fenton@visfleet.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "lib/ternary_logic.rb",
26
+ "spec/spec_helper.rb",
27
+ "spec/ternary_logic_spec.rb",
28
+ "ternary_logic.gemspec"
29
+ ]
30
+ s.homepage = %q{http://github.com/visfleet/ternary_logic}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.6}
34
+ s.summary = %q{Ternary logic support for Ruby, True, False, Unknown}
35
+ s.test_files = [
36
+ "spec/spec_helper.rb",
37
+ "spec/ternary_logic_spec.rb"
38
+ ]
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ else
46
+ end
47
+ else
48
+ end
49
+ end
50
+
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ternary_logic
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Aisha Fenton
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-22 00:00:00 +12:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: aisha.fenton@visfleet.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - .document
32
+ - .gitignore
33
+ - LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION
37
+ - lib/ternary_logic.rb
38
+ - spec/spec_helper.rb
39
+ - spec/ternary_logic_spec.rb
40
+ - ternary_logic.gemspec
41
+ has_rdoc: true
42
+ homepage: http://github.com/visfleet/ternary_logic
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.6
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Ternary logic support for Ruby, True, False, Unknown
71
+ test_files:
72
+ - spec/spec_helper.rb
73
+ - spec/ternary_logic_spec.rb