Class: CodePoetry::Stat
- Inherits:
-
Object
- Object
- CodePoetry::Stat
- Defined in:
- lib/code_poetry/stat.rb
Instance Attribute Summary collapse
-
#churns ⇒ Object
Returns the value of attribute churns.
-
#complexity ⇒ Object
Returns the value of attribute complexity.
-
#complexity_per_method ⇒ Object
Returns the value of attribute complexity_per_method.
-
#definition_complexity ⇒ Object
Returns the value of attribute definition_complexity.
-
#duplication ⇒ Object
readonly
Returns the value of attribute duplication.
-
#duplications ⇒ Object
Returns the value of attribute duplications.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#lines_of_code ⇒ Object
readonly
Returns the value of attribute lines_of_code.
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#smells ⇒ Object
Returns the value of attribute smells.
Instance Method Summary collapse
- #get_method(name) ⇒ Object
- #get_method_at_line(line) ⇒ Object
-
#initialize(file) ⇒ Stat
constructor
A new instance of Stat.
- #round_definition_complexity ⇒ Object
- #set_churns(churns) ⇒ Object
- #set_method_complexity(name, score) ⇒ Object
- #set_smells ⇒ Object
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
#churns ⇒ Object
Returns the value of attribute churns.
11 12 13 |
# File 'lib/code_poetry/stat.rb', line 11 def churns @churns end |
#complexity ⇒ Object
Returns the value of attribute complexity.
11 12 13 |
# File 'lib/code_poetry/stat.rb', line 11 def complexity @complexity end |
#complexity_per_method ⇒ Object
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_complexity ⇒ Object
Returns the value of attribute definition_complexity.
11 12 13 |
# File 'lib/code_poetry/stat.rb', line 11 def definition_complexity @definition_complexity end |
#duplication ⇒ Object (readonly)
Returns the value of attribute duplication.
10 11 12 |
# File 'lib/code_poetry/stat.rb', line 10 def duplication @duplication end |
#duplications ⇒ Object
Returns the value of attribute duplications.
12 13 14 |
# File 'lib/code_poetry/stat.rb', line 12 def duplications @duplications end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
10 11 12 |
# File 'lib/code_poetry/stat.rb', line 10 def file @file end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
10 11 12 |
# File 'lib/code_poetry/stat.rb', line 10 def lines @lines end |
#lines_of_code ⇒ Object (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 |
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
10 11 12 |
# File 'lib/code_poetry/stat.rb', line 10 def methods @methods end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/code_poetry/stat.rb', line 10 def name @name end |
#smells ⇒ Object
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_complexity ⇒ Object
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_smells ⇒ Object
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 |