Class: Cobplexity::Analyzer
- Inherits:
-
Object
- Object
- Cobplexity::Analyzer
- Defined in:
- lib/cobplexity/analyzer.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#group ⇒ Object
Returns the value of attribute group.
-
#threshold ⇒ Object
Returns the value of attribute threshold.
Instance Method Summary collapse
- #analyze ⇒ Object
- #analyze_file ⇒ Object
- #analyze_paragraph(paragraph) ⇒ Object
-
#initialize ⇒ Analyzer
constructor
A new instance of Analyzer.
Constructor Details
#initialize ⇒ Analyzer
Returns a new instance of Analyzer.
5 6 7 8 9 10 |
# File 'lib/cobplexity/analyzer.rb', line 5 def initialize @files = [] @threshold = 0 @group = "APPLICATION" @metrics = [] end |
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
4 5 6 |
# File 'lib/cobplexity/analyzer.rb', line 4 def files @files end |
#group ⇒ Object
Returns the value of attribute group.
4 5 6 |
# File 'lib/cobplexity/analyzer.rb', line 4 def group @group end |
#threshold ⇒ Object
Returns the value of attribute threshold.
4 5 6 |
# File 'lib/cobplexity/analyzer.rb', line 4 def threshold @threshold end |
Instance Method Details
#analyze ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/cobplexity/analyzer.rb', line 11 def analyze @files.each do |file| Dir.glob file do |filename| @filename = filename analyze_file end end @metrics end |
#analyze_file ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/cobplexity/analyzer.rb', line 20 def analyze_file File.open @filename do |file| program = Module.new file.readlines.join program.paragraphs.each do |paragraph| analyze_paragraph paragraph end end end |
#analyze_paragraph(paragraph) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/cobplexity/analyzer.rb', line 28 def analyze_paragraph paragraph metric = Metric.new metric.size = paragraph.lines metric.color = @threshold == 0 ? paragraph.complexity : @threshold - paragraph.complexity metric.categories << @group metric.categories << @filename metric.categories << paragraph.name @metrics << metric end |