Class: CodePoetry::Stat
- Inherits:
-
Object
- Object
- CodePoetry::Stat
- Defined in:
- lib/code_poetry/stat.rb
Instance Attribute Summary collapse
-
#absolute_path ⇒ Object
readonly
Returns the value of attribute absolute_path.
-
#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.
-
#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.
-
#relative_path ⇒ Object
readonly
Returns the value of attribute relative_path.
-
#smells ⇒ Object
Returns the value of attribute smells.
Instance Method Summary collapse
- #get_method(name) ⇒ Object
- #get_method_at_line(line) ⇒ Object
-
#initialize(path, project_path) ⇒ 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(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_path ⇒ Object (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 |
#churns ⇒ Object
Returns the value of attribute churns.
12 13 14 |
# File 'lib/code_poetry/stat.rb', line 12 def churns @churns end |
#complexity ⇒ Object
Returns the value of attribute complexity.
12 13 14 |
# File 'lib/code_poetry/stat.rb', line 12 def complexity @complexity end |
#complexity_per_method ⇒ Object
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_complexity ⇒ Object
Returns the value of attribute definition_complexity.
13 14 15 |
# File 'lib/code_poetry/stat.rb', line 13 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.
13 14 15 |
# File 'lib/code_poetry/stat.rb', line 13 def duplications @duplications 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.
11 12 13 |
# File 'lib/code_poetry/stat.rb', line 11 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 |
#relative_path ⇒ Object (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 |
#smells ⇒ Object
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_complexity ⇒ Object
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_smells ⇒ Object
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 |