Class: Bmg::Summarizer::Positional

Inherits:
Bmg::Summarizer show all
Defined in:
lib/bmg/summarizer/positional.rb

Overview

See First and Last

Direct Known Subclasses

First, Last

Instance Attribute Summary collapse

Attributes inherited from Bmg::Summarizer

#functor, #options

Instance Method Summary collapse

Methods inherited from Bmg::Summarizer

avg, bucketize, by_proc, collect, concat, count, distinct, distinct_count, first, last, max, median, median_cont, median_disc, min, multiple, percentile, percentile_cont, percentile_disc, stddev, sum, summarization, #summarize, #to_summarizer_name, value_by, variance

Constructor Details

#initialize(*args, &block) ⇒ Positional

Returns a new instance of Positional.

Raises:

  • (ArgumentError)


6
7
8
9
10
# File 'lib/bmg/summarizer/positional.rb', line 6

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

Instance Attribute Details

#orderingObject (readonly)

Returns the value of attribute ordering.



11
12
13
# File 'lib/bmg/summarizer/positional.rb', line 11

def ordering
  @ordering
end

Instance Method Details

#finalize(memo) ⇒ Object



26
27
28
29
# File 'lib/bmg/summarizer/positional.rb', line 26

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

#happens(memo, tuple) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/bmg/summarizer/positional.rb', line 17

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

#leastObject



13
14
15
# File 'lib/bmg/summarizer/positional.rb', line 13

def least
  nil
end