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(path, project_path) ⇒ Stat

Returns a new instance of Stat.



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

def initialize(path, project_path)
  @absolute_path = path
  @relative_path = path.sub("#{project_path}/", '')
  @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

#absolute_pathObject (readonly)

Returns the value of attribute absolute_path.



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

def absolute_path
  @absolute_path
end

#churnsObject

Returns the value of attribute churns.



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

def churns
  @churns
end

#complexityObject

Returns the value of attribute complexity.



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

def complexity
  @complexity
end

#complexity_per_methodObject

Returns the value of attribute complexity_per_method.



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

def complexity_per_method
  @complexity_per_method
end

#definition_complexityObject

Returns the value of attribute definition_complexity.



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

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.



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

def duplications
  @duplications
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.



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

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

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



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

def relative_path
  @relative_path
end

#smellsObject

Returns the value of attribute smells.



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

def smells
  @smells
end

Instance Method Details

#get_method(name) ⇒ Object



30
31
32
# File 'lib/code_poetry/stat.rb', line 30

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

#get_method_at_line(line) ⇒ Object



42
43
44
45
46
# File 'lib/code_poetry/stat.rb', line 42

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

#round_definition_complexityObject



60
61
62
# File 'lib/code_poetry/stat.rb', line 60

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

#set_churns(churns) ⇒ Object



26
27
28
# File 'lib/code_poetry/stat.rb', line 26

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

#set_method_complexity(name, score) ⇒ Object



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

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

#set_smellsObject



48
49
50
51
52
# File 'lib/code_poetry/stat.rb', line 48

def set_smells
  set_class_smells
  set_method_smells
  set_duplication_smells
end