Sha256: d9ac17a57e4411ca10c5b7bc13c2b8fbe825d8415a7921cdb69a24e26c2cda0b
Contents?: true
Size: 913 Bytes
Versions: 11
Compression:
Stored size: 913 Bytes
Contents
module MotionPrime module FilterMixin def filter_array(data, find_options = {}, sort_options = nil) data = data.select do |entity| find_options.all? do |field, value| if value.is_a?(Array) value.include?(entity.info[field].to_s) else entity.info[field] == value end end end if find_options.present? data.sort! do |a, b| left_part = [] right_part = [] sort_options[:sort].each do |(k,v)| left = a.send(k) right = b.send(k) if left.class != right.class left = left.to_s right = right.to_s end left, right = right, left if v.to_s == 'desc' left_part << left right_part << right end left_part <=> right_part end if sort_options.try(:[], :sort).present? data end end end
Version data entries
11 entries across 11 versions & 1 rubygems