Sha256: b0d2c8903e6b15ab1bb29251e36f456c242af367a923453f22f45a6a82342908
Contents?: true
Size: 727 Bytes
Versions: 5
Compression:
Stored size: 727 Bytes
Contents
require_relative './enum' require_relative '../../exceptions' module Dentaku module AST class Pluck < Enum def self.min_param_count 2 end def self.max_param_count 2 end def value(context = {}) collection = Array(@args[0].value(context)) unless collection.all? { |elem| elem.is_a?(Hash) } raise ArgumentError.for(:incompatible_type, value: collection), 'PLUCK() requires first argument to be an array of hashes' end 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
5 entries across 5 versions & 2 rubygems