Class: ClosestNeighbours::Grouper::GrouperHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/closest_neighbours/grouper.rb

Overview

Helper class to index data and extract ranges from an enumberble

Instance Method Summary collapse

Constructor Details

#initialize(groups, data) ⇒ GrouperHelper

Returns a new instance of GrouperHelper.



27
28
29
30
# File 'lib/closest_neighbours/grouper.rb', line 27

def initialize(groups, data)
  @groups = groups
  @data = data
end

Instance Method Details

#callObject



32
33
34
35
36
37
38
39
40
# File 'lib/closest_neighbours/grouper.rb', line 32

def call
  if groups == 1
    [data]
  elsif groups >= data.count
    cells + blanks
  else
    ranges.map { |range| data[range] }
  end
end