Class: Cobplexity::Module
- Inherits:
-
Object
- Object
- Cobplexity::Module
- Defined in:
- lib/cobplexity/module.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#paragraphs ⇒ Object
readonly
Returns the value of attribute paragraphs.
Instance Method Summary collapse
- #analyze_code ⇒ Object
- #count_module ⇒ Object
- #count_paragraph ⇒ Object
-
#initialize(code = '') ⇒ Module
constructor
A new instance of Module.
- #reset_data ⇒ Object
Constructor Details
#initialize(code = '') ⇒ Module
Returns a new instance of Module.
5 6 7 |
# File 'lib/cobplexity/module.rb', line 5 def initialize code='' self.code = code end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
4 5 6 |
# File 'lib/cobplexity/module.rb', line 4 def code @code end |
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
4 5 6 |
# File 'lib/cobplexity/module.rb', line 4 def lines @lines end |
#paragraphs ⇒ Object (readonly)
Returns the value of attribute paragraphs.
4 5 6 |
# File 'lib/cobplexity/module.rb', line 4 def paragraphs @paragraphs end |
Instance Method Details
#analyze_code ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cobplexity/module.rb', line 12 def analyze_code reset_data @code.lines.each do |line| @line = Line.new line if @line.procedure_division? reset_data else count_module count_paragraph end end end |
#count_module ⇒ Object
28 29 30 |
# File 'lib/cobplexity/module.rb', line 28 def count_module @lines += 1 if @line.code? end |
#count_paragraph ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/cobplexity/module.rb', line 31 def count_paragraph @paragraphs << Paragraph.new(@line.paragraph_name) if @line.paragraph? if @line.code? && !@paragraphs.last.nil? @paragraphs.last.lines += 1 @paragraphs.last.complexity += @line.branches end end |
#reset_data ⇒ Object
24 25 26 27 |
# File 'lib/cobplexity/module.rb', line 24 def reset_data @lines = 0 @paragraphs = [] end |