Sha256: e2807d1f642e2d29daf719aafdcadbc40cb8ba09bd392f0b7a7d95fd5c6fee27

Contents?: true

Size: 707 Bytes

Versions: 25

Compression:

Stored size: 707 Bytes

Contents

module Bmg
  class Summarizer
    # See First and Last
    class Positional < Summarizer

      def initialize(*args, &block)
        super
        raise ArgumentError, "Missing order" unless options[:order]
        @ordering = Ordering.new(options[:order])
      end
      attr_reader :ordering

      def least
        nil
      end

      def happens(memo, tuple)
        if memo.nil?
          tuple
        else
          c = ordering.call(memo, tuple)
          c <= 0 ? choose(memo, tuple) : choose(tuple, memo)
        end
      end

      def finalize(memo)
        return nil if memo.nil?
        extract_value(memo)
      end

    end # class Positional
  end # class Summarizer
end # module Bmg

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
bmg-0.18.13 lib/bmg/summarizer/positional.rb
bmg-0.18.12 lib/bmg/summarizer/positional.rb
bmg-0.18.11 lib/bmg/summarizer/positional.rb
bmg-0.18.10 lib/bmg/summarizer/positional.rb
bmg-0.18.9 lib/bmg/summarizer/positional.rb