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.

Instance Method Summary collapse

Constructor Details

#initialize(&sorter) ⇒ DistinctList

Returns a new instance of DistinctList.



139
140
141
# File 'lib/bmg/operator/autosummarize.rb', line 139

def initialize(&sorter)
  @sorter = sorter
end

Instance Method Details

#init(v) ⇒ Object



143
144
145
# File 'lib/bmg/operator/autosummarize.rb', line 143

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

#inspectObject Also known as: to_s



158
159
160
# File 'lib/bmg/operator/autosummarize.rb', line 158

def inspect
  ":group"
end

#sum(v1, v2) ⇒ Object



147
148
149
150
# File 'lib/bmg/operator/autosummarize.rb', line 147

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

#term(v) ⇒ Object



152
153
154
155
156
# File 'lib/bmg/operator/autosummarize.rb', line 152

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