Class: CodePoetry::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/code_poetry/stat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Stat

Returns a new instance of Stat.



14
15
16
17
18
19
20
21
22
# File 'lib/code_poetry/stat.rb', line 14

def initialize(file)
  @file = file
  @lines_of_code, @churns = 0, 0
  @complexity, @complexity_per_method, @definition_complexity = 0, 0, 0
  @methods, @smells, @duplications = [], [], []
  @lines = {}

  parse_file
end

Instance Attribute Details

#churnsObject

Returns the value of attribute churns.



11
12
13
# File 'lib/code_poetry/stat.rb', line 11

def churns
  @churns
end

#complexityObject

Returns the value of attribute complexity.



11
12
13
# File 'lib/code_poetry/stat.rb', line 11

def complexity
  @complexity
end

#complexity_per_methodObject

Returns the value of attribute complexity_per_method.



11
12
13
# File 'lib/code_poetry/stat.rb', line 11

def complexity_per_method
  @complexity_per_method
end

#definition_complexityObject

Returns the value of attribute definition_complexity.



11
12
13
# File 'lib/code_poetry/stat.rb', line 11

def definition_complexity
  @definition_complexity
end

#duplicationObject (readonly)

Returns the value of attribute duplication.



10
11
12
# File 'lib/code_poetry/stat.rb', line 10

def duplication
  @duplication
end

#duplicationsObject

Returns the value of attribute duplications.



12
13
14
# File 'lib/code_poetry/stat.rb', line 12

def duplications
  @duplications
end

#fileObject (readonly)

Returns the value of attribute file.



10
11
12
# File 'lib/code_poetry/stat.rb', line 10

def file
  @file
end

#linesObject (readonly)

Returns the value of attribute lines.



10
11
12
# File 'lib/code_poetry/stat.rb', line 10

def lines
  @lines
end

#lines_of_codeObject (readonly)

Returns the value of attribute lines_of_code.



10
11
12
# File 'lib/code_poetry/stat.rb', line 10

def lines_of_code
  @lines_of_code
end

#methodsObject (readonly)

Returns the value of attribute methods.



10
11
12
# File 'lib/code_poetry/stat.rb', line 10

def methods
  @methods
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/code_poetry/stat.rb', line 10

def name
  @name
end

#smellsObject

Returns the value of attribute smells.



12
13
14
# File 'lib/code_poetry/stat.rb', line 12

def smells
  @smells
end

Instance Method Details

#get_method(name) ⇒ Object



28
29
30
# File 'lib/code_poetry/stat.rb', line 28

def get_method(name)
  @methods.detect { |method| method.name == name }
end

#get_method_at_line(line) ⇒ Object



40
41
42
# File 'lib/code_poetry/stat.rb', line 40

def get_method_at_line(line)
  @methods.detect { |method| method.first_line <= line && method.last_line >= line }
end

#round_definition_complexityObject



54
55
56
# File 'lib/code_poetry/stat.rb', line 54

def round_definition_complexity
  @definition_complexity = @definition_complexity.round(0)
end

#set_churns(churns) ⇒ Object



24
25
26
# File 'lib/code_poetry/stat.rb', line 24

def set_churns(churns)
  @churns = churns if churns
end

#set_method_complexity(name, score) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/code_poetry/stat.rb', line 32

def set_method_complexity(name, score)
  if method = get_method(name)
    method.complexity = score.round(0)
  else
    @definition_complexity += score
  end
end

#set_smellsObject



44
45
46
47
48
# File 'lib/code_poetry/stat.rb', line 44

def set_smells
  set_class_smells
  set_method_smells
  set_duplication_smells
end