Class: RubyCritic::AnalysedModulesCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rubycritic/core/analysed_modules_collection.rb

Constant Summary collapse

COST_LIMIT =

Limit used to prevent very bad modules to have excessive impact in the overall result. See #limited_cost_for

32
MAX_SCORE =

Score goes from 0 (worst) to 100 (perfect)

100
ZERO_SCORE_COST =

Projects with an average cost of 16 (or above) will score 0, since 16 is where the worst possible rating (F) starts

16
COST_MULTIPLIER =
MAX_SCORE.to_f / ZERO_SCORE_COST

Instance Method Summary collapse

Constructor Details

#initialize(paths) ⇒ AnalysedModulesCollection

Returns a new instance of AnalysedModulesCollection.



19
20
21
22
23
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 19

def initialize(paths)
  @modules = SourceLocator.new(paths).pathnames.map do |pathname|
    AnalysedModule.new(pathname: pathname)
  end
end

Instance Method Details

#each(&block) ⇒ Object



25
26
27
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 25

def each(&block)
  @modules.each(&block)
end

#scoreObject



33
34
35
36
37
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 33

def score
  MAX_SCORE - average_limited_cost * COST_MULTIPLIER
rescue
  0.0
end

#to_json(*options) ⇒ Object



29
30
31
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 29

def to_json(*options)
  @modules.to_json(*options)
end