Module: Searchlight::Options

Defined in:
lib/searchlight/options.rb

Class Method Summary collapse

Class Method Details

.checked?(value) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/searchlight/options.rb', line 10

def self.checked?(value)
  !(['0', 'false', ''].include?(value.to_s.strip))
end

.empty?(value) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# 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