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.0
MAX_SCORE =

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

100.0
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.0
COST_MULTIPLIER =
MAX_SCORE / ZERO_SCORE_COST

Instance Method Summary collapse

Constructor Details

#initialize(paths, modules = nil) ⇒ AnalysedModulesCollection

Returns a new instance of AnalysedModulesCollection.


20
21
22
23
24
25
26
27
28
29
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 20

def initialize(paths, modules = nil)
  @modules = SourceLocator.new(paths).pathnames.map do |pathname|
    if modules
      analysed_module = modules.find { |mod| mod.pathname == pathname }
      build_analysed_module(analysed_module)
    else
      AnalysedModule.new(pathname: pathname)
    end
  end
end

Instance Method Details

#each(&block) ⇒ Object


31
32
33
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 31

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

#find(module_path) ⇒ Object


39
40
41
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 39

def find(module_path)
  @modules.find { |mod| mod.pathname == module_path }
end

#for_rating(rating) ⇒ Object


59
60
61
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 59

def for_rating(rating)
  find_all { |mod| mod.rating.to_s == rating }
end

#scoreObject


47
48
49
50
51
52
53
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 47

def score
  if @modules.any?
    (MAX_SCORE - average_limited_cost * COST_MULTIPLIER).round(2)
  else
    0.0
  end
end

#summaryObject


55
56
57
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 55

def summary
  AnalysisSummary.generate(self)
end

#to_json(*options) ⇒ Object


43
44
45
# File 'lib/rubycritic/core/analysed_modules_collection.rb', line 43

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

#where(module_paths) ⇒ Object


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

def where(module_paths)
  @modules.find_all { |mod| module_paths.include? mod.path }
end