ruby-watchr 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/watchr/file_analyse.rb +2 -1
- data/lib/watchr/rating.rb +29 -0
- data/lib/watchr/version.rb +1 -1
- data/spec/watchr/rating_spec.rb +32 -0
- metadata +6 -3
data/lib/watchr/file_analyse.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'watchr/flog_metric/report'
|
2
2
|
require 'watchr/smell'
|
3
3
|
require 'watchr/smells_collector'
|
4
|
-
|
5
4
|
require 'watchr/analysers/flog'
|
5
|
+
require 'watchr/rating'
|
6
6
|
|
7
7
|
module Watchr
|
8
8
|
#
|
@@ -12,6 +12,7 @@ module Watchr
|
|
12
12
|
#
|
13
13
|
class FileAnalyse
|
14
14
|
include Analysers::Flog
|
15
|
+
include Rating
|
15
16
|
|
16
17
|
attr_reader :path
|
17
18
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Watchr
|
2
|
+
module Rating
|
3
|
+
include SmellTypes
|
4
|
+
|
5
|
+
def rating
|
6
|
+
total = smells.reduce(0) {|total, smell| total += rate(smell)}
|
7
|
+
|
8
|
+
[100, 60, 40, 20, 10].each_with_index do |limit, i|
|
9
|
+
return %w(F E D C B A)[i] if total > limit
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def rate(smell)
|
16
|
+
case smell.type
|
17
|
+
when COMPLEX_METHOD,
|
18
|
+
VERY_COMPLEX_METHOD,
|
19
|
+
COMPLEX_OBJECT,
|
20
|
+
VERY_COMPLEX_OBJECT
|
21
|
+
smell.options.total_score
|
22
|
+
|
23
|
+
when IDENTICAL_CODE,
|
24
|
+
SIMILAR_CODE
|
25
|
+
smell.options.mass
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/watchr/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'watchr/rating'
|
3
|
+
|
4
|
+
describe Watchr::Rating do
|
5
|
+
|
6
|
+
let(:complexity_smell) {
|
7
|
+
stub('smell',
|
8
|
+
:type => Watchr::SmellTypes::COMPLEX_METHOD,
|
9
|
+
:options => stub(:total_score => 29.3))
|
10
|
+
}
|
11
|
+
|
12
|
+
let(:duplication_smell) {
|
13
|
+
stub('smell',
|
14
|
+
:type => Watchr::SmellTypes::IDENTICAL_CODE,
|
15
|
+
:options => stub(:mass => 72))
|
16
|
+
}
|
17
|
+
|
18
|
+
let(:smells) { [complexity_smell, duplication_smell] }
|
19
|
+
|
20
|
+
let(:analyse) {
|
21
|
+
analyse = stub('analyse', :smells => smells)
|
22
|
+
analyse.extend Watchr::Rating
|
23
|
+
|
24
|
+
analyse
|
25
|
+
}
|
26
|
+
|
27
|
+
describe '#rating' do
|
28
|
+
subject { analyse.rating }
|
29
|
+
|
30
|
+
it { should == 'F' }
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Petr Janda
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-07-
|
17
|
+
date: 2012-07-08 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/watchr/flog_metric/report.rb
|
83
83
|
- lib/watchr/location.rb
|
84
84
|
- lib/watchr/paths.rb
|
85
|
+
- lib/watchr/rating.rb
|
85
86
|
- lib/watchr/smell.rb
|
86
87
|
- lib/watchr/smell_types.rb
|
87
88
|
- lib/watchr/smells_collector.rb
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- spec/watchr/flog_metric/flog_matric/flog_report_spec.rb
|
97
98
|
- spec/watchr/location_spec.rb
|
98
99
|
- spec/watchr/paths_spec.rb
|
100
|
+
- spec/watchr/rating_spec.rb
|
99
101
|
- spec/watchr/smell_spec.rb
|
100
102
|
- spec/watchr/smells_collector_spec.rb
|
101
103
|
- watchr.gemspec
|
@@ -142,5 +144,6 @@ test_files:
|
|
142
144
|
- spec/watchr/flog_metric/flog_matric/flog_report_spec.rb
|
143
145
|
- spec/watchr/location_spec.rb
|
144
146
|
- spec/watchr/paths_spec.rb
|
147
|
+
- spec/watchr/rating_spec.rb
|
145
148
|
- spec/watchr/smell_spec.rb
|
146
149
|
- spec/watchr/smells_collector_spec.rb
|