truther 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +6 -6
- data/lib/{truthy.rb → truther.rb} +7 -7
- data/lib/truther/version.rb +3 -0
- data/spec/{truthy_spec.rb → truther_spec.rb} +2 -2
- data/{truthy.gemspec → truther.gemspec} +2 -2
- metadata +6 -6
- data/lib/truthy/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a1c06e2b96b3d63caee3be42c1840ff5f437a34
|
4
|
+
data.tar.gz: c9a9938aafea95e6e26d0c580e1e003cd156e8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14a10bb03ada51f7de1cf5500843e4bb912735b9f7ffefff9ef121561498e42d8c161f4b480f71b12a35aca7f5a97e2f385cc2a9ffc3a084e3e4c7d81610c6b1
|
7
|
+
data.tar.gz: 085e59b948a886ede2c699e66ce170e03c9d6373151931129eea3e9d830c858ee6786cac16634514053a9fb6ac53c72f441217d92c2feb3c39c3298702b3d8ba
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# Truther
|
2
2
|
|
3
|
-
Easy convertion to boolean from
|
3
|
+
Easy convertion to boolean from truther and falsy values.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem '
|
9
|
+
gem 'truther'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
@@ -14,7 +14,7 @@ And then execute:
|
|
14
14
|
|
15
15
|
Or install it yourself as:
|
16
16
|
|
17
|
-
$ gem install
|
17
|
+
$ gem install truther
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
@@ -24,15 +24,15 @@ Use `#to_b` on `String`, `Integer`, `Float`, `nil`, `true` or `false`.
|
|
24
24
|
|
25
25
|
'no'.to_b == false
|
26
26
|
|
27
|
-
Check `
|
27
|
+
Check `Truther::TRUTHER_STRINGS` and `Truther::FALSY_STRINGS` to find out how strings are mapped to boolean.
|
28
28
|
|
29
|
-
An unrecognized string will raise `
|
29
|
+
An unrecognized string will raise `Truther::NeitherTrueNoFalseError` unless a default value is provided. In which case the default value will be returned.
|
30
30
|
|
31
31
|
'maybe'.to_b(:i_dont_know) == :i_dont_know
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
1. Fork it ( http://github.com/stephanebisson/
|
35
|
+
1. Fork it ( http://github.com/stephanebisson/truther/fork )
|
36
36
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
37
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
38
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require "
|
1
|
+
require "truther/version"
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module Truther
|
4
|
+
TRUTHER_STRINGS = ['true', '1', 'yes', 'y', 'oui', 'vrai']
|
5
5
|
FALSY_STRINGS = ['false', '0', 'no', 'n', 'non', 'faux']
|
6
6
|
|
7
7
|
class NeitherTrueNoFalseError < StandardError
|
8
8
|
def initialize(str)
|
9
|
-
super("'#{str}' is not recognized as
|
9
|
+
super("'#{str}' is not recognized as truther or falsy.")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -14,11 +14,11 @@ end
|
|
14
14
|
class String
|
15
15
|
def to_b(when_not_recognized=:raise)
|
16
16
|
sanitized_string = self.downcase.strip
|
17
|
-
return true if
|
18
|
-
return false if
|
17
|
+
return true if Truther::TRUTHER_STRINGS.include? sanitized_string
|
18
|
+
return false if Truther::FALSY_STRINGS.include? sanitized_string
|
19
19
|
|
20
20
|
if when_not_recognized == :raise
|
21
|
-
raise
|
21
|
+
raise Truther::NeitherTrueNoFalseError.new sanitized_string
|
22
22
|
else
|
23
23
|
when_not_recognized
|
24
24
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'truther'
|
2
2
|
|
3
3
|
describe :to_b do
|
4
4
|
|
@@ -23,7 +23,7 @@ describe :to_b do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'raises error on unrecognized strings' do
|
26
|
-
expect {'asdf'.to_b}.to raise_error
|
26
|
+
expect {'asdf'.to_b}.to raise_error Truther::NeitherTrueNoFalseError
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns default on unrecognized strings' do
|
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'truther/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "truther"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Truther::VERSION
|
9
9
|
spec.authors = ["Stephane Bisson"]
|
10
10
|
spec.email = ["stephane.c.bisson@gmail.com"]
|
11
11
|
spec.summary = "Converts many strings to their boolean value."
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: truther
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephane Bisson
|
@@ -64,10 +64,10 @@ files:
|
|
64
64
|
- LICENSE.txt
|
65
65
|
- README.md
|
66
66
|
- Rakefile
|
67
|
-
- lib/
|
68
|
-
- lib/
|
69
|
-
- spec/
|
70
|
-
-
|
67
|
+
- lib/truther.rb
|
68
|
+
- lib/truther/version.rb
|
69
|
+
- spec/truther_spec.rb
|
70
|
+
- truther.gemspec
|
71
71
|
homepage: ''
|
72
72
|
licenses:
|
73
73
|
- MIT
|
@@ -93,4 +93,4 @@ signing_key:
|
|
93
93
|
specification_version: 4
|
94
94
|
summary: Converts many strings to their boolean value.
|
95
95
|
test_files:
|
96
|
-
- spec/
|
96
|
+
- spec/truther_spec.rb
|
data/lib/truthy/version.rb
DELETED