Class: Portunus::TypeCasters::Boolean
- Inherits:
-
Object
- Object
- Portunus::TypeCasters::Boolean
- Defined in:
- lib/portunus/type_casters/boolean.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cast ⇒ Object
-
#initialize(value:) ⇒ Boolean
constructor
A new instance of Boolean.
- #uncast ⇒ Object
Constructor Details
#initialize(value:) ⇒ Boolean
Returns a new instance of Boolean.
12 13 14 |
# File 'lib/portunus/type_casters/boolean.rb', line 12 def initialize(value:) @value = value end |
Class Method Details
.cast(value:) ⇒ Object
4 5 6 |
# File 'lib/portunus/type_casters/boolean.rb', line 4 def self.cast(value:) new(value: value).cast end |
.uncast(value:) ⇒ Object
8 9 10 |
# File 'lib/portunus/type_casters/boolean.rb', line 8 def self.uncast(value:) new(value: value).uncast end |
Instance Method Details
#cast ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/portunus/type_casters/boolean.rb', line 16 def cast if [false, nil, "false", 0].include?(value) "false" else "true" end end |