Class: HasSetting::Formatters::BooleanFormatter

Inherits:
NilSafeFormatter show all
Defined in:
lib/has_setting/formatters.rb

Overview

Convert a Boolean to String and Back nil, ‘0’, false, 0 and ” are considered __false__, everything else is __true__ This is not like ruby where only nil and false are considered __false__

Instance Method Summary collapse

Methods inherited from NilSafeFormatter

#to_s, #to_type

Instance Method Details

#safe_to_s(value) ⇒ Object



53
54
55
# File 'lib/has_setting/formatters.rb', line 53

def safe_to_s(value)
  value && value != '0' && value != 0 && value != '' ? '1' : '0'
end

#safe_to_type(value) ⇒ Object



50
51
52
# File 'lib/has_setting/formatters.rb', line 50

def safe_to_type(value)
  value == '1'
end