Sha256: 1269d68934c2a9f93de503cd2202f7a16b636b64830830cfd117c2b141dfa60a
Contents?: true
Size: 898 Bytes
Versions: 18
Compression:
Stored size: 898 Bytes
Contents
module Origen module Tester module Parser class SearchableHash < ::Hash def where(conditions) exact = conditions.delete(:exact) results = SearchableArray.new each do |_key, item| if conditions.all? do |attr, val| if val.is_a?(Array) if exact val.any? { |v| item.send(attr).to_s == v.to_s } else val.any? { |v| item.send(attr).to_s =~ /#{v.to_s}/ } end else if exact item.send(attr).to_s == val.to_s else item.send(attr).to_s =~ /#{val.to_s}/ end end end results << item end end results end end end end end
Version data entries
18 entries across 18 versions & 1 rubygems