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.



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

def initialize(&sorter)
  @sorter = sorter
end

Instance Method Details

#init(v) ⇒ Object



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

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

#inspectObject Also known as: to_s



228
229
230
# File 'lib/bmg/operator/autosummarize.rb', line 228

def inspect
  ":group"
end

#sum(v1, v2) ⇒ Object



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

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

#term(v) ⇒ Object



222
223
224
225
226
# File 'lib/bmg/operator/autosummarize.rb', line 222

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