Method: Inspec::Resources::Shadow#filter

Defined in:
lib/inspec/resources/shadow.rb

#filter(query = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/inspec/resources/shadow.rb', line 70

def filter(query = {})
  return self if query.nil? || query.empty?

  res = set_params
  filters = ""
  query.each do |attr, condition|
    condition = condition.to_s if condition.is_a? Integer
    filters += " #{attr} = #{condition.inspect}"
    res = res.find_all do |line|
      case line[attr.to_s]
      when condition
        true
      else
        false
      end
    end
  end
  content = res.map { |x| x.values.join(":") }.join("\n")
  Shadow.new(@path, content: content, filters: @filters + filters)
end