Sha256: 78129526df482b94a936852d3d02199d3569d7ba1603ebe4b7889f64d8ffad6c

Contents?: true

Size: 555 Bytes

Versions: 3

Compression:

Stored size: 555 Bytes

Contents

require_relative '../function'
require_relative '../../exceptions'

module Dentaku
  module AST
    class Pluck < Function
      def self.min_param_count
        2
      end

      def self.max_param_count
        2
      end

      def deferred_args
        [1]
      end

      def value(context = {})
        collection = @args[0].value(context)
        pluck_path = @args[1].identifier

        collection.map { |h| h.transform_keys(&:to_s)[pluck_path] }
      end
    end
  end
end

Dentaku::AST::Function.register_class(:pluck, Dentaku::AST::Pluck)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dentaku-3.4.2 lib/dentaku/ast/functions/pluck.rb
dentaku-3.4.1 lib/dentaku/ast/functions/pluck.rb
dentaku-3.4.0 lib/dentaku/ast/functions/pluck.rb