Class: Bmg::Operator::Autosummarize::YByX
- Inherits:
-
Object
- Object
- Bmg::Operator::Autosummarize::YByX
- 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
- #init(v) ⇒ Object
-
#initialize(y, x, preserve_nulls = false) ⇒ YByX
constructor
A new instance of YByX.
- #inspect ⇒ Object (also: #to_s)
- #sum(v1, v2) ⇒ Object
- #term(v) ⇒ Object
Constructor Details
#initialize(y, x, preserve_nulls = false) ⇒ YByX
Returns a new instance of YByX.
242 243 244 245 246 |
# File 'lib/bmg/operator/autosummarize.rb', line 242 def initialize(y, x, preserve_nulls = false) @y = y @x = x @preserve_nulls = preserve_nulls end |
Instance Method Details
#init(v) ⇒ Object
248 249 250 |
# File 'lib/bmg/operator/autosummarize.rb', line 248 def init(v) v.nil? ? [] : [v] end |
#inspect ⇒ Object Also known as: to_s
265 266 267 |
# File 'lib/bmg/operator/autosummarize.rb', line 265 def inspect ":#{@y}_by_#{@x}" end |
#sum(v1, v2) ⇒ Object
252 253 254 |
# File 'lib/bmg/operator/autosummarize.rb', line 252 def sum(v1, v2) v2.nil? ? v1 : (v1 << v2) end |
#term(v) ⇒ Object
256 257 258 259 260 261 262 263 |
# File 'lib/bmg/operator/autosummarize.rb', line 256 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 |