Class: DecisionAgent::Dmn::Feel::Functions::Mean

Inherits:
Base
  • Object
show all
Defined in:
lib/decision_agent/dmn/feel/functions.rb

Class Method Summary collapse

Methods inherited from Base

register, validate_arg_count

Class Method Details

.call(args, _context = {}) ⇒ Object



262
263
264
265
266
267
268
269
# File 'lib/decision_agent/dmn/feel/functions.rb', line 262

def self.call(args, _context = {})
  validate_arg_count(args, 1)
  list = args[0]
  return 0 unless list.is_a?(Array) || list.is_a?(Types::List)
  return 0 if list.empty?

  list.map(&:to_f).sum / list.length.to_f
end