Sha256: eb37a2cdb37f034045a9097d68ea09aeba59f6dbfa62aae7251516f9dd2c36c7

Contents?: true

Size: 658 Bytes

Versions: 1

Compression:

Stored size: 658 Bytes

Contents

module AmoCRM::Resources::WhereFilter

  # Возвращает список элементов по переданному фильтру.
  # Например:
  # > universe.features.where goodUuid: uuid
  #
  # @return [Array of AmoCRM::Entities::Base]
  #
  def where filter
    values.select { |v| filtered? v, filter }
  end

  # Возвращает первый найденный по фильтру элемент или
  # nil
  #
  # @return AmoCRM::Entities::Base || nil
  def findWhere filter
    where(filter).first
  end

  private

  def filtered? o, filter={}
    filter.select { |k,v| o.send(k)==v }.count == filter.keys.count
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amo_crm-0.2.2 lib/amo_crm/resources/where_filter.rb