Class: Bmg::Operator::Autosummarize::YByX

Inherits:
Object
  • Object
show all
Defined in:
lib/bmg/operator/autosummarize.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(y, x, preserve_nulls = false) ⇒ YByX

Returns a new instance of YByX.



171
172
173
174
175
# File 'lib/bmg/operator/autosummarize.rb', line 171

def initialize(y, x, preserve_nulls = false)
  @y = y
  @x = x
  @preserve_nulls = preserve_nulls
end

Instance Method Details

#init(v) ⇒ Object



177
178
179
# File 'lib/bmg/operator/autosummarize.rb', line 177

def init(v)
  [v]
end

#inspectObject Also known as: to_s



194
195
196
# File 'lib/bmg/operator/autosummarize.rb', line 194

def inspect
  ":#{y}_by_#{x}"
end

#sum(v1, v2) ⇒ Object



181
182
183
# File 'lib/bmg/operator/autosummarize.rb', line 181

def sum(v1, v2)
  v1 << v2
end

#term(v) ⇒ Object



185
186
187
188
189
190
191
192
# File 'lib/bmg/operator/autosummarize.rb', line 185

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