Sha256: 017c154c74a5caaa0bea15e2d5f9585507b4a1997e15b1367c9965d4d8be7fcf

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

# encoding: utf-8

module Axiom
  class Aggregate

    # The maximum value in a sequence of numbers
    class Maximum < Aggregate

      DEFAULT = -Float::INFINITY

      # Return the maximum value for a sequence of numbers
      #
      # @example
      #   maximum = Maximum.call(maximum, value)
      #
      # @param [Numeric] maximum
      #
      # @param [Numeric] value
      #
      # @return [Numeric]
      #
      # @api public
      def self.call(maximum, value)
        return maximum if value.nil?
        value > maximum ? value : maximum
      end

      # Return the type returned from #call
      #
      # @example
      #   type = aggregate.type  # => Axiom::Types::Numeric
      #
      # @return [Class<Types::Numeric>]
      #
      # @api public
      def type
        Attribute.infer_type(operand)
      end

      module Methods
        extend Aliasable

        inheritable_alias(max: :maximum)

        # Return a maximum aggregate function
        #
        # @example
        #   maximum = attribute.maximum
        #
        # @param [Attribute]
        #
        # @return [Maximum]
        #
        # @api public
        def maximum
          Maximum.new(self)
        end

      end # module Methods
    end # class Maximum
  end # class Aggregate
end # module Axiom

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
axiom-0.2.0 lib/axiom/aggregate/maximum.rb
axiom-0.1.1 lib/axiom/aggregate/maximum.rb