Class: Bmg::Operator::Autosummarize::DistinctList

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

Overview

Summarizes by putting distinct dependents inside an Array, ignoring nils, and optionally sorting the array.

Constant Summary collapse

INSTANCE =
new

Instance Method Summary collapse

Constructor Details

#initialize(&sorter) ⇒ DistinctList

Returns a new instance of DistinctList.



206
207
208
# File 'lib/bmg/operator/autosummarize.rb', line 206

def initialize(&sorter)
  @sorter = sorter
end

Instance Method Details

#init(v) ⇒ Object



210
211
212
# File 'lib/bmg/operator/autosummarize.rb', line 210

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

#inspect ⇒ Object Also known as: to_s



225
226
227
# File 'lib/bmg/operator/autosummarize.rb', line 225

def inspect
  ":group"
end

#sum(v1, v2) ⇒ Object



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

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

#term(v) ⇒ Object



219
220
221
222
223
# File 'lib/bmg/operator/autosummarize.rb', line 219

def term(v)
  v = v.to_a
  v = v.sort(&@sorter) if @sorter
  v
end