Class: Cobplexity::Module

Inherits:
Object
  • Object
show all
Defined in:
lib/cobplexity/module.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject

Returns the value of attribute code.



4
5
6
# File 'lib/cobplexity/module.rb', line 4

def code
  @code
end

#linesObject (readonly)

Returns the value of attribute lines.



4
5
6
# File 'lib/cobplexity/module.rb', line 4

def lines
  @lines
end

#paragraphsObject (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_codeObject



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_moduleObject



28
29
30
# File 'lib/cobplexity/module.rb', line 28

def count_module
  @lines += 1 if @line.code? 
end

#count_paragraphObject



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_dataObject



24
25
26
27
# File 'lib/cobplexity/module.rb', line 24

def reset_data
  @lines = 0
  @paragraphs = []
end