Class: CodeRatioHeuristic
- Inherits:
-
Object
- Object
- CodeRatioHeuristic
- Defined in:
- lib/tipster/heuristics/code_ratio_heuristic.rb
Instance Attribute Summary collapse
-
#production_lines_of_code ⇒ Object
readonly
Returns the value of attribute production_lines_of_code.
-
#test_lines_of_code ⇒ Object
readonly
Returns the value of attribute test_lines_of_code.
Instance Method Summary collapse
- #apply(changed_files) ⇒ Object
- #has_production_code? ⇒ Boolean
-
#initialize ⇒ CodeRatioHeuristic
constructor
A new instance of CodeRatioHeuristic.
- #pass? ⇒ Boolean
- #process(file) ⇒ Object
- #ratio ⇒ Object
Constructor Details
#initialize ⇒ CodeRatioHeuristic
Returns a new instance of CodeRatioHeuristic.
7 8 9 10 11 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 7 def initialize @passing_ratio = 0.0 @test_lines_of_code = 0 @production_lines_of_code = 0 end |
Instance Attribute Details
#production_lines_of_code ⇒ Object (readonly)
Returns the value of attribute production_lines_of_code.
5 6 7 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 5 def production_lines_of_code @production_lines_of_code end |
#test_lines_of_code ⇒ Object (readonly)
Returns the value of attribute test_lines_of_code.
5 6 7 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 5 def test_lines_of_code @test_lines_of_code end |
Instance Method Details
#apply(changed_files) ⇒ Object
13 14 15 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 13 def apply(changed_files) changed_files.each { |file| process(file) } end |
#has_production_code? ⇒ Boolean
31 32 33 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 31 def has_production_code? @production_lines_of_code > 0 end |
#pass? ⇒ Boolean
35 36 37 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 35 def pass? has_production_code? ? ratio > @passing_ratio : true end |
#process(file) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 17 def process(file) if file.file_name =~ /(spec|test)/i @test_lines_of_code += file.lines_modified elsif file.file_name =~ /(cs|rb|java)$/ @production_lines_of_code += file.lines_modified end end |
#ratio ⇒ Object
27 28 29 |
# File 'lib/tipster/heuristics/code_ratio_heuristic.rb', line 27 def ratio @test_lines_of_code.to_f / @production_lines_of_code.to_f end |