Sha256: 5e1a038f314cc55c0aa3b7b6b747e7bdbb0d149f776ed82adb33fb312e68e75e
Contents?: true
Size: 436 Bytes
Versions: 3
Compression:
Stored size: 436 Bytes
Contents
require_relative '../function' Dentaku::AST::Function.register(:avg, :numeric, ->(*args) { flatten_args = args.flatten if flatten_args.empty? raise Dentaku::ArgumentError.for( :too_few_arguments, function_name: 'AVG()', at_least: 1, given: 0 ), 'AVG() requires at least one argument' end flatten_args.map { |arg| Dentaku::AST::Function.numeric(arg) }.reduce(0, :+) / BigDecimal(flatten_args.length) })
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dentaku-3.5.4 | lib/dentaku/ast/functions/avg.rb |
dentaku-3.5.3 | lib/dentaku/ast/functions/avg.rb |
dentaku-3.5.2 | lib/dentaku/ast/functions/avg.rb |