Module: CIMI::Helpers::FilterResourceMethods

Included in:
Model::Resource
Defined in:
lib/cimi/helpers/filter_helper.rb

Instance Method Summary collapse

Instance Method Details

#filter_by(filter_opts) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cimi/helpers/filter_helper.rb', line 20

def filter_by(filter_opts)
  return self if filter_opts.nil?
  return self unless kind_of? CIMI::Model::Collection
  attribute, value = parse_filter_opts(filter_opts)
  if attribute =~ /\!$/
    attribute.chomp!('!')
    self.entries.delete_if { |entry| entry[attribute.to_sym] == value }
  else
    self.entries.delete_if { |entry| entry[attribute.to_sym] != value }
  end
  self
end

#parse_filter_opts(opts) ⇒ Object



33
34
35
36
37
# File 'lib/cimi/helpers/filter_helper.rb', line 33

def parse_filter_opts(opts)
  attribute, value = opts.split('=')
  value.gsub!(/\A("|')|("|')\Z/, '')
  [attribute, value]
end