module ActiveHash::CustomMatchable::ClassMethods

Public Instance Methods

like(options) click to toggle source
# File lib/active_hash/custom_matchable.rb, line 11
def like(options)
  where(options.inject({}) do |likes, (column, pattern)|
    likes[column] = ActiveHash::Matcher::Like.new(pattern)
    likes
  end)
end
where(options) click to toggle source
# File lib/active_hash/custom_matchable.rb, line 18
def where(options)
  return @records if options.nil?
  (@records || []).select do |record|
    options.all? do |col, matcher|
      if matcher.respond_to?(:call)
        matcher.call(record[col])
      elsif col.to_sym == :or
        ActiveHash::Matcher::Or.new(matcher).call(record)
      else
        record[col] == matcher
      end
    end
  end
end