Sha256: cb6893e0df633d2173d148954c8a75e22db07c8a09f54d71418b9a879d6f44db

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true


module Recollect
  module Array
    require_relative 'array/utility'
    require_relative 'array/hashie'
    require_relative 'array/predicate/startify'
    require_relative 'array/predicate/endify'
    require_relative 'array/predicate/equal'
    require_relative 'array/predicate/contains'
    require_relative 'array/predicate/in'
    require_relative 'array/predicate/less_than'
    require_relative 'array/predicate/greater_than'
    require_relative 'array/filterable'


    # ### Array.filter
    # `filter value into Array using conditions
    #
    # ````
    # data = [{ a: 1, b: { c: 2 }, d: ['1'] }]
    # filters = { a_eq: 1, 'b.c_eq': 2, d_in: ['1'] }
    # Recollect::Array.filter(data, filters)
    # ````
    def self.filter(data, filters = {})
      Filterable.call(data, filters)
    end

    # ### Array.pluck
    # `fetch value into Array, like Lodash#pluck`
    #
    # ````
    # data = [{ a: 1, b: { c: 2 }, d: ['1'] }]
    # Recollect::Array.pluck(data, 'b.c')
    # ````
    def self.pluck(data, iteratee)
      return [] unless data.any?

      data.map { |item| Hashie.get(item, iteratee) }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
recollect-array-0.1.4 lib/recollect/array.rb
recollect-array-0.1.3 lib/recollect/array.rb
recollect-array-0.1.2 lib/recollect/array.rb
recollect-array-0.1.1 lib/recollect/array.rb
recollect-array-0.1.0 lib/recollect/array.rb