Class: RubyLens::Model::DependencyAggregation

Inherits:
Object
  • Object
show all
Defined in:
lib/rubylens/model/dependency_aggregation.rb

Constant Summary collapse

SIGNAL_COLUMNS =
(1..6).freeze

Instance Method Summary collapse

Constructor Details

#initialize(package_count:) ⇒ DependencyAggregation

Returns a new instance of DependencyAggregation.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
# File 'lib/rubylens/model/dependency_aggregation.rb', line 8

def initialize(package_count:)
  raise ArgumentError, "package_count must be nonnegative" if package_count.negative?

  @ruby_counts = Array.new(package_count) { Array.new(4, 0) }
  @signal_maxima = Array.new(6, 0)
  @rows = Array.new(package_count) { [] }
end

Instance Method Details

#add(package_index:, row:, construct_index:) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rubylens/model/dependency_aggregation.rb', line 16

def add(package_index:, row:, construct_index:)
  local_index = @rows[package_index].length
  @ruby_counts[package_index][construct_index] += 1 if construct_index
  maxima = @signal_maxima
  column = SIGNAL_COLUMNS.begin
  while column <= SIGNAL_COLUMNS.end
    value = row[column]
    index = column - 1
    maxima[index] = value if value > maxima[index]
    column += 1
  end
  @rows[package_index] << (row.frozen? ? row : row.dup.freeze)
  local_index
end

#packagesObject



31
32
33
34
35
36
37
38
# File 'lib/rubylens/model/dependency_aggregation.rb', line 31

def packages
  @rows.each_index.map do |index|
    {
      ruby_counts: @ruby_counts[index].dup.freeze,
      declarations: @rows[index].dup.freeze,
    }.freeze
  end.freeze
end

#signal_maximaObject



40
41
42
# File 'lib/rubylens/model/dependency_aggregation.rb', line 40

def signal_maxima
  @signal_maxima.dup.freeze
end