Class: Attractor::Suggester

Inherits:
Object
  • Object
show all
Defined in:
lib/attractor/suggester.rb

Overview

makes suggestions for refactorings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = []) ⇒ Suggester

Returns a new instance of Suggester.



8
9
10
# File 'lib/attractor/suggester.rb', line 8

def initialize(values = [])
  @values = values
end

Instance Attribute Details

#valuesObject

Returns the value of attribute values.



6
7
8
# File 'lib/attractor/suggester.rb', line 6

def values
  @values
end

Instance Method Details

#suggest(threshold = 95) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/attractor/suggester.rb', line 12

def suggest(threshold = 95)
  products = @values.map(&:score)
  products.extend(DescriptiveStatistics)
  quantile = products.percentile(threshold.to_i)

  @values.select { |val| val.score > quantile }
    .sort_by { |val| val.score }.reverse
end