class Bmg::YsByX
Summarizes by converting dependents to { x => [ys], … } such that `x` is not null and `[ys]` is a distinct list of observed non-null `y`.
Public Class Methods
new(y, x, &sorter)
click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 230 def initialize(y, x, &sorter) @y = y @x = x @sorter = sorter end
Public Instance Methods
init(v)
click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 236 def init(v) v.nil? ? [] : [v] end
inspect()
click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 256 def inspect ":#{@y}s_by_#{@x}" end
Also aliased as: to_s
sum(v1, v2)
click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 240 def sum(v1, v2) v2.nil? ? v1 : (v1 << v2) end
term(v)
click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 244 def term(v) h = {} v = v.reject{|tuple| tuple[@x].nil? } v = v.sort(&@sorter) if @sorter v.each do |tuple| h[tuple[@x]] ||= [] h[tuple[@x]] << tuple[@y] h[tuple[@x]].uniq! end h end