Class: SnFoil::Searcher::Boolean

Inherits:
Object
  • Object
show all
Defined in:
lib/snfoil/searcher/boolean.rb

Overview

A class that behaves like a boolean type, including rules for coercion of user input.

Coercion

  • “false”, “f” , “0”, 0 or any other value in FALSE_VALUES will be coerced to false

  • Empty strings are coerced to nil

  • All other values will be coerced to true

Since:

  • 0.1.0

Constant Summary collapse

FALSE_VALUES =

rubocop:disable Lint/BooleanSymbol

Since:

  • 0.1.0

[
  false, 0,
  '0', :'0',
  'f', :f,
  'F', :F,
  'false', :false,
  'FALSE', :FALSE,
  'off', :off,
  'OFF', :OFF,
  '', nil
].to_set.freeze

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object

rubocop:enable Lint/BooleanSymbol

Since:

  • 0.1.0



51
52
53
# File 'lib/snfoil/searcher/boolean.rb', line 51

def cast(value)
  !FALSE_VALUES.include?(value)
end