Class: Bmg::Operator::Autosummarize::YsByX

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

Overview

Summarizes by converting dependents to { x => [ys], … } such that ‘x` is not null and `[ys]` is a distinct list of observed non-null `y`.

Instance Method Summary collapse

Constructor Details

#initialize(y, x, &sorter) ⇒ YsByX

Returns a new instance of YsByX.



207
208
209
210
211
# File 'lib/bmg/operator/autosummarize.rb', line 207

def initialize(y, x, &sorter)
  @y = y
  @x = x
  @sorter = sorter
end

Instance Method Details

#init(v) ⇒ Object



213
214
215
# File 'lib/bmg/operator/autosummarize.rb', line 213

def init(v)
  [v]
end

#inspectObject Also known as: to_s



233
234
235
# File 'lib/bmg/operator/autosummarize.rb', line 233

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

#sum(v1, v2) ⇒ Object



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

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

#term(v) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/bmg/operator/autosummarize.rb', line 221

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