certainty 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +20 -4
- data/certainty.gemspec +1 -1
- data/lib/certainty.rb +7 -7
- data/lib/certainty/version.rb +1 -1
- data/test/certainty_test.rb +2 -1
- metadata +5 -5
data/README.md
CHANGED
@@ -1,12 +1,28 @@
|
|
1
|
-
#
|
1
|
+
# Certainty
|
2
2
|
|
3
|
-
|
3
|
+
Certainty provides __Boolean__, an object that represents truth in
|
4
|
+
Ruby.
|
4
5
|
|
5
|
-
|
6
|
+
The library posits three truth values: true, false, or unknown.
|
7
|
+
|
8
|
+
[![travis](https://secure.travis-ci.org/hakanensari/certainty.png)](http://travis-ci.org/hakanensari/certainty)
|
6
9
|
|
7
10
|
## Usage
|
8
11
|
|
9
|
-
|
12
|
+
Add to your Gemfile.
|
13
|
+
|
14
|
+
gem 'certainty'
|
15
|
+
|
16
|
+
Require.
|
17
|
+
|
18
|
+
require 'certainty'
|
19
|
+
|
20
|
+
Inquire.
|
10
21
|
|
11
22
|
true.is_a? Boolean
|
12
23
|
=> true
|
24
|
+
|
25
|
+
Typecast.
|
26
|
+
|
27
|
+
Boolean("false")
|
28
|
+
=> false
|
data/certainty.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["code@papercavalier.com"]
|
10
10
|
s.homepage = "http://github.com/hakanensari/certainty"
|
11
11
|
s.summary = %q{An object that represents truth}
|
12
|
-
s.description = %q{Certainty
|
12
|
+
s.description = %q{Certainty provides Boolean, an object that represents truth.}
|
13
13
|
|
14
14
|
s.rubyforge_project = "certainty"
|
15
15
|
|
data/lib/certainty.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# = Certainty
|
2
2
|
#
|
3
|
-
#
|
3
|
+
# Certainty provides +Boolean+, an object that represents truth.
|
4
4
|
module Boolean; end
|
5
5
|
|
6
|
-
|
6
|
+
# The library posits three truth values: true, false, or unknown.
|
7
|
+
[FalseClass, NilClass, TrueClass].each do |klass|
|
7
8
|
klass.send :include, Boolean
|
8
9
|
end
|
9
10
|
|
@@ -26,7 +27,7 @@ end
|
|
26
27
|
|
27
28
|
class String
|
28
29
|
# Returns +true+ if, downcased, the receiver is +"1"+ or +"true"+,
|
29
|
-
# +false+ if
|
30
|
+
# +false+ if +"0"+ or +"false"+, or +nil+ otherwise.
|
30
31
|
def to_bool
|
31
32
|
{
|
32
33
|
'1' => true,
|
@@ -39,8 +40,8 @@ class String
|
|
39
40
|
end
|
40
41
|
|
41
42
|
class Numeric
|
42
|
-
# Returns +
|
43
|
-
# +1.0+, +false+ if
|
43
|
+
# Returns +true+ if the receiver, converted to float, is equal to
|
44
|
+
# +1.0+, +false+ if +0.0+, or +nil+ otherwise.
|
44
45
|
def to_bool
|
45
46
|
{
|
46
47
|
1.0 => true,
|
@@ -51,8 +52,7 @@ class Numeric
|
|
51
52
|
end
|
52
53
|
|
53
54
|
module Kernel
|
54
|
-
# Converts _arg_ to a boolean object
|
55
|
-
# knowable.
|
55
|
+
# Converts _arg_ to a boolean object.
|
56
56
|
def Boolean(arg)
|
57
57
|
arg.to_bool
|
58
58
|
end
|
data/lib/certainty/version.rb
CHANGED
data/test/certainty_test.rb
CHANGED
@@ -8,8 +8,9 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class TestCertainty < Test::Unit::TestCase
|
10
10
|
def test_existence
|
11
|
-
assert_kind_of Boolean, true
|
12
11
|
assert_kind_of Boolean, false
|
12
|
+
assert_kind_of Boolean, nil
|
13
|
+
assert_kind_of Boolean, true
|
13
14
|
end
|
14
15
|
|
15
16
|
def test_boolean_representation
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: certainty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-24 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
|
-
description: Certainty
|
14
|
+
description: Certainty provides Boolean, an object that represents truth.
|
15
15
|
email:
|
16
16
|
- code@papercavalier.com
|
17
17
|
executables: []
|
@@ -41,7 +41,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
41
|
version: '0'
|
42
42
|
segments:
|
43
43
|
- 0
|
44
|
-
hash:
|
44
|
+
hash: -2904344466707709946
|
45
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
46
|
none: false
|
47
47
|
requirements:
|
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
50
|
version: '0'
|
51
51
|
segments:
|
52
52
|
- 0
|
53
|
-
hash:
|
53
|
+
hash: -2904344466707709946
|
54
54
|
requirements: []
|
55
55
|
rubyforge_project: certainty
|
56
56
|
rubygems_version: 1.8.6
|