truther 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/truther.rb +2 -2
- data/lib/truther/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54aea950d590f54f8bfcc8ef3669dc04c172b7c6
|
4
|
+
data.tar.gz: 52e0879672c656972531a0be3a5e52049f857559
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ecfcc7e515c88064ce099b881a584ed6304c7e92dcb4567873d5afcdf847dff907a446b486ff8475f5395357ae150d1ab5b31fcc441a37a76ac6b04bec678c3
|
7
|
+
data.tar.gz: 427bcd9d4ae939fccbc3b6ba5cb884b6600c95bf5ea7003d7d992744c12dd43feb98cf42fc278bdb92d4e44d41002a67a08e0280d2b3ec5d97af6919765f587a
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Use `#to_b` on `String`, `Integer`, `Float`, `nil`, `true` or `false`.
|
|
24
24
|
|
25
25
|
'no'.to_b == false
|
26
26
|
|
27
|
-
Check `Truther::
|
27
|
+
Check `Truther::TRUTHY_STRINGS` and `Truther::FALSY_STRINGS` to find out how strings are mapped to boolean.
|
28
28
|
|
29
29
|
An unrecognized string will raise `Truther::NeitherTrueNorFalseError` unless a default value is provided. In which case the default value will be returned.
|
30
30
|
|
data/lib/truther.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "truther/version"
|
2
2
|
|
3
3
|
module Truther
|
4
|
-
|
4
|
+
TRUTHY_STRINGS = ['true', '1', 'yes', 'y', 'oui', 'vrai']
|
5
5
|
FALSY_STRINGS = ['false', '0', 'no', 'n', 'non', 'faux']
|
6
6
|
|
7
7
|
class NeitherTrueNorFalseError < StandardError
|
@@ -14,7 +14,7 @@ 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 Truther::
|
17
|
+
return true if Truther::TRUTHY_STRINGS.include? sanitized_string
|
18
18
|
return false if Truther::FALSY_STRINGS.include? sanitized_string
|
19
19
|
|
20
20
|
if when_not_recognized == :raise
|
data/lib/truther/version.rb
CHANGED