Class: Rubycritic::AnalysedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycritic/core/analysed_file.rb

Instance Method Summary collapse

Instance Method Details

#complexity_per_methodObject



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

def complexity_per_method
  if methods_count == 0
    "N/A"
  else
    complexity.fdiv(methods_count).round(1)
  end
end

#costObject



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

def cost
  @cost ||= smells.map(&:cost).inject(0, :+) + (complexity / 25)
end

#has_smells?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rubycritic/core/analysed_file.rb', line 41

def has_smells?
  !smells.empty?
end

#nameObject



17
18
19
# File 'lib/rubycritic/core/analysed_file.rb', line 17

def name
  @name ||= pathname.basename.sub_ext("").to_s
end

#pathObject



21
22
23
# File 'lib/rubycritic/core/analysed_file.rb', line 21

def path
  @path ||= pathname.to_s
end

#ratingObject



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

def rating
  @rating ||= Rating.from_cost(cost)
end

#smells_at_location(location) ⇒ Object



45
46
47
# File 'lib/rubycritic/core/analysed_file.rb', line 45

def smells_at_location(location)
  smells.select { |smell| smell.at_location?(location) }
end