truther 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/truther.rb +2 -2
- data/lib/truther/version.rb +1 -1
- data/spec/truther_spec.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: 2fe0a6a29afc15aceb4c9679437dd5d00a57b5f7
|
4
|
+
data.tar.gz: 120efec8142397b22cc9f1fc580f39fada80d3c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09f13256e5314469710b9937c6438d20dd7877707e7a7f76a1b3d725b0e5b9820f6a1a6840c7978e07b17755a0e942f5b8ad0797b07d13ac251d406d91544d56
|
7
|
+
data.tar.gz: fa090e0ede76cf70a75d45edd7872d7d4f3b0858e842f00f9316c94d1251409d4cc4eb6d73dc4ae323a2cbfd9e8a5eb2809bd940c0bbf02a421e770cf52c75c8
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Use `#to_b` on `String`, `Integer`, `Float`, `nil`, `true` or `false`.
|
|
26
26
|
|
27
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 `Truther::
|
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
|
|
31
31
|
'maybe'.to_b(:i_dont_know) == :i_dont_know
|
32
32
|
|
data/lib/truther.rb
CHANGED
@@ -4,7 +4,7 @@ module Truther
|
|
4
4
|
TRUTHER_STRINGS = ['true', '1', 'yes', 'y', 'oui', 'vrai']
|
5
5
|
FALSY_STRINGS = ['false', '0', 'no', 'n', 'non', 'faux']
|
6
6
|
|
7
|
-
class
|
7
|
+
class NeitherTrueNorFalseError < StandardError
|
8
8
|
def initialize(str)
|
9
9
|
super("'#{str}' is not recognized as truther or falsy.")
|
10
10
|
end
|
@@ -18,7 +18,7 @@ class String
|
|
18
18
|
return false if Truther::FALSY_STRINGS.include? sanitized_string
|
19
19
|
|
20
20
|
if when_not_recognized == :raise
|
21
|
-
raise Truther::
|
21
|
+
raise Truther::NeitherTrueNorFalseError.new sanitized_string
|
22
22
|
else
|
23
23
|
when_not_recognized
|
24
24
|
end
|
data/lib/truther/version.rb
CHANGED
data/spec/truther_spec.rb
CHANGED
@@ -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 Truther::
|
26
|
+
expect {'asdf'.to_b}.to raise_error Truther::NeitherTrueNorFalseError
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'returns default on unrecognized strings' do
|