class Bmg::YByX

Summarizes by converting dependents to { x => y, … } such that `x` is not null and `y` is the value observed for `x`.

Public Class Methods

new(y, x, preserve_nulls = false) click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 194
def initialize(y, x, preserve_nulls = false)
  @y = y
  @x = x
  @preserve_nulls = preserve_nulls
end

Public Instance Methods

init(v) click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 200
def init(v)
  v.nil? ? [] : [v]
end
inspect() click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 217
def inspect
  ":#{@y}_by_#{@x}"
end
Also aliased as: to_s
sum(v1, v2) click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 204
def sum(v1, v2)
  v2.nil? ? v1 : (v1 << v2)
end
term(v) click to toggle source
# File lib/bmg/operator/autosummarize.rb, line 208
def term(v)
  h = {}
  v.each do |tuple|
    next if tuple[@x].nil?
    h[tuple[@x]] = tuple[@y] if not tuple[@y].nil? or @preserve_nulls
  end
  h
end
to_s()
Alias for: inspect