Class: ActiveGraph::Shared::TypeConverters::BooleanConverter
- Inherits:
-
BaseConverter
- Object
- BaseConverter
- ActiveGraph::Shared::TypeConverters::BooleanConverter
- Defined in:
- lib/active_graph/shared/type_converters.rb
Constant Summary collapse
- FALSE_VALUES =
%w(n N no No NO false False FALSE off Off OFF f F).to_set
Class Method Summary collapse
- .converted?(value) ⇒ Boolean
- .converted_values ⇒ Object
- .db_type ⇒ Object (also: convert_type)
- .to_db(value) ⇒ Object (also: to_ruby)
Methods inherited from BaseConverter
Class Method Details
.converted?(value) ⇒ Boolean
192 193 194 |
# File 'lib/active_graph/shared/type_converters.rb', line 192 def converted?(value) converted_values.include?(value) end |
.converted_values ⇒ Object
196 197 198 |
# File 'lib/active_graph/shared/type_converters.rb', line 196 def converted_values [true, false] end |
.db_type ⇒ Object Also known as: convert_type
200 201 202 |
# File 'lib/active_graph/shared/type_converters.rb', line 200 def db_type ActiveGraph::Shared::Boolean end |
.to_db(value) ⇒ Object Also known as: to_ruby
206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/active_graph/shared/type_converters.rb', line 206 def to_db(value) return false if FALSE_VALUES.include?(value) case value when TrueClass, FalseClass value when Numeric, /^\-?[0-9]/ !value.to_f.zero? else value.present? end end |