Class: ActiveAttr::Typecasting::BooleanTypecaster
- Inherits:
-
Object
- Object
- ActiveAttr::Typecasting::BooleanTypecaster
- Defined in:
- lib/active_attr/typecasting/boolean_typecaster.rb
Overview
Typecasts an Object to true or false
Constant Summary collapse
- FALSE_VALUES =
Values which force a false result for typecasting
These values are based on the YAML language.
["n", "N", "no", "No", "NO", "false", "False", "FALSE", "off", "Off", "OFF", "f", "F"]
Instance Method Summary collapse
-
#call(value) ⇒ true, false
Typecasts an object to true or false.
Instance Method Details
#call(value) ⇒ true, false
Typecasts an object to true or false
Similar to ActiveRecord, when the attribute is a zero value or is a string that represents false, typecasting returns false. Otherwise typecasting just checks the presence of a value.
34 35 36 37 38 39 40 |
# File 'lib/active_attr/typecasting/boolean_typecaster.rb', line 34 def call(value) case value when *FALSE_VALUES then false when Numeric, /^\-?[0-9]/ then !value.to_f.zero? else value.present? end end |