Class: ParamsReady::Value::BooleanCoder

Inherits:
Coder show all
Defined in:
lib/params_ready/value/coder.rb

Direct Known Subclasses

CheckboxBooleanCoder

Class Method Summary collapse

Methods inherited from Coder

instance

Methods included from Coercion

#strict_default?, #try_coerce

Methods inherited from AbstractCoder

value_class_name

Methods included from Extensions::ClassReaderWriter

#class_reader_writer

Class Method Details

.coerce(input, _) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/params_ready/value/coder.rb', line 129

def self.coerce(input, _)
  return nil if input.nil? || input == ''
  return input if input.is_a?(TrueClass) || input.is_a?(FalseClass)
  str = input.to_s
  case str
  when 'true', 'TRUE', 't', 'T', '1'
    true
  when 'false', 'FALSE', 'f', 'F', '0'
    false
  else
    raise
  end
end

.format(value, format) ⇒ Object



143
144
145
# File 'lib/params_ready/value/coder.rb', line 143

def self.format(value, format)
  value.to_s
end