module Searchlight::Options

Public Class Methods

checked?(value) click to toggle source
# File lib/searchlight/options.rb, line 10
def self.checked?(value)
  !(['0', 'false', ''].include?(value.to_s.strip))
end
empty?(value) click to toggle source
# File lib/searchlight/options.rb, line 3
def self.empty?(value)
  return true if value.nil?
  return true if value.respond_to?(:empty?) && value.empty?
  return true if /\A[[:space:]]*\z/ === value
  false
end
excluding_empties(input) click to toggle source
# File lib/searchlight/options.rb, line 14
def self.excluding_empties(input)
  output = input.dup
  output.each do |key, value|
    if value.is_a?(Hash)
      output[key] = value.reject { |_, v| empty?(v) }
    end
    if value.instance_of?(Array)
      output[key] = value.reject { |v| empty?(v) }
    end
  end
  output.reject { |_, value| empty?(value) }
end