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.



239
240
241
242
243
# File 'lib/bmg/operator/autosummarize.rb', line 239

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

Instance Method Details

#init(v) ⇒ Object



245
246
247
# File 'lib/bmg/operator/autosummarize.rb', line 245

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

#inspect ⇒ Object Also known as: to_s



262
263
264
# File 'lib/bmg/operator/autosummarize.rb', line 262

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

#sum(v1, v2) ⇒ Object



249
250
251
# File 'lib/bmg/operator/autosummarize.rb', line 249

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

#term(v) ⇒ Object



253
254
255
256
257
258
259
260
# File 'lib/bmg/operator/autosummarize.rb', line 253

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