class Dentaku::AST::Pluck
Public Class Methods
max_param_count()
click to toggle source
# File lib/dentaku/ast/functions/pluck.rb, line 11 def self.max_param_count 3 end
min_param_count()
click to toggle source
# File lib/dentaku/ast/functions/pluck.rb, line 7 def self.min_param_count 2 end
Public Instance Methods
value(context = {})
click to toggle source
# File lib/dentaku/ast/functions/pluck.rb, line 15 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 default = @args[2] collection.map { |h| h.transform_keys(&:to_s).fetch(pluck_path, default&.value(context)) } end