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.



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

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

Instance Method Details

#init(v) ⇒ Object



200
201
202
# File 'lib/bmg/operator/autosummarize.rb', line 200

def init(v)
  v.nil? ? [] : [v]
end

#inspectObject Also known as: to_s



217
218
219
# File 'lib/bmg/operator/autosummarize.rb', line 217

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

#sum(v1, v2) ⇒ Object



204
205
206
# File 'lib/bmg/operator/autosummarize.rb', line 204

def sum(v1, v2)
  v2.nil? ? v1 : (v1 << v2)
end

#term(v) ⇒ Object



208
209
210
211
212
213
214
215
# 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