Class: LcpRuby::Search::ParamSanitizer
- Inherits:
-
Object
- Object
- LcpRuby::Search::ParamSanitizer
- Defined in:
- lib/lcp_ruby/search/param_sanitizer.rb
Constant Summary collapse
- TRUTHY =
%w[true 1 t yes].freeze
- FALSY =
%w[false 0 f no].freeze
Class Method Summary collapse
-
.normalize_boolean(value) ⇒ Object
Normalizes a value to boolean if it matches common truthy/falsy strings.
-
.reject_blanks(params_hash) ⇒ Object
Removes key-value pairs where the value is a blank string.
Class Method Details
.normalize_boolean(value) ⇒ Object
Normalizes a value to boolean if it matches common truthy/falsy strings. Returns the original value unchanged if it doesn’t match.
17 18 19 20 21 22 |
# File 'lib/lcp_ruby/search/param_sanitizer.rb', line 17 def self.normalize_boolean(value) str = value.to_s.downcase return true if TRUTHY.include?(str) return false if FALSY.include?(str) value end |
.reject_blanks(params_hash) ⇒ Object
Removes key-value pairs where the value is a blank string. Preserves nil, false, 0, and non-string blanks.
9 10 11 12 13 |
# File 'lib/lcp_ruby/search/param_sanitizer.rb', line 9 def self.reject_blanks(params_hash) return {} if params_hash.blank? params_hash.reject { |_, v| v.is_a?(String) && v.blank? } end |