module CIMI::Helpers::FilterResourceMethods

Public Instance Methods

filter_by(filter_opts) click to toggle source
# 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 =~ %r\!$/
    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) click to toggle source
# File lib/cimi/helpers/filter_helper.rb, line 33
def parse_filter_opts(opts)
  attribute, value = opts.split('=')
  value.gsub!(%r\A("|')|("|')\Z/, '')
  [attribute, value]
end