Class: Validation::Rule::Boolean
- Inherits:
-
Object
- Object
- Validation::Rule::Boolean
- Defined in:
- lib/diaspora_federation/validators/rules/boolean.rb
Overview
Boolean validation rule
Valid is:
-
a
String
: “true”, “false”, “t”, “f”, “yes”, “no”, “y”, “n”, “1”, “0” -
a
Integer
: 1 or 0 -
a
Boolean
: true or false
Instance Method Summary collapse
-
#error_key ⇒ Symbol
The error key for this rule.
-
#params ⇒ Hash
This rule has no params.
-
#valid_value?(value) ⇒ Boolean
Determines if value is a valid
boolean
.
Instance Method Details
#error_key ⇒ Symbol
The error key for this rule
14 15 16 |
# File 'lib/diaspora_federation/validators/rules/boolean.rb', line 14 def error_key :boolean end |
#params ⇒ Hash
This rule has no params.
34 35 36 |
# File 'lib/diaspora_federation/validators/rules/boolean.rb', line 34 def params {} end |
#valid_value?(value) ⇒ Boolean
Determines if value is a valid boolean
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/diaspora_federation/validators/rules/boolean.rb', line 19 def valid_value?(value) return false if value.nil? case value when String true if value =~ /\A(true|false|t|f|yes|no|y|n|1|0)\z/i when Integer true if [1, 0].include?(value) else [true, false].include?(value) end end |