Class: Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/analyst/analyzer.rb

Constant Summary collapse

CONDITIONALS =
[:if, :or_asgn, :and_asgn, :or, :and]
DEFAULT_CLASS_NAME =
"Unknown"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ Analyzer

Returns a new instance of Analyzer.



11
12
13
14
15
16
# File 'lib/analyst/analyzer.rb', line 11

def initialize(content)
  self.content = content
  self.edges = 0
  self.nodes = 1
  self.exits = 1
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



7
8
9
# File 'lib/analyst/analyzer.rb', line 7

def class_name
  @class_name
end

#contentObject

Returns the value of attribute content.



7
8
9
# File 'lib/analyst/analyzer.rb', line 7

def content
  @content
end

#edgesObject

Returns the value of attribute edges.



7
8
9
# File 'lib/analyst/analyzer.rb', line 7

def edges
  @edges
end

#exitsObject

Returns the value of attribute exits.



7
8
9
# File 'lib/analyst/analyzer.rb', line 7

def exits
  @exits
end

#nodesObject

Returns the value of attribute nodes.



7
8
9
# File 'lib/analyst/analyzer.rb', line 7

def nodes
  @nodes
end

Instance Method Details

#complexityObject



18
19
20
21
# File 'lib/analyst/analyzer.rb', line 18

def complexity
  return unless traverse(parsed)
  self.edges - self.nodes + exits
end

#constantsObject



31
32
33
# File 'lib/analyst/analyzer.rb', line 31

def constants
  @constants ||= constants_from(parsed)
end

#extract_class_nameObject



43
44
45
46
47
# File 'lib/analyst/analyzer.rb', line 43

def extract_class_name
  return self.class_name if self.class_name && ! self.class_name.empty?
  found = find_class(parsed)
  self.class_name = ! found.empty? && found || DEFAULT_CLASS_NAME
end

#extract_methodsObject



39
40
41
# File 'lib/analyst/analyzer.rb', line 39

def extract_methods
  @methods ||= methods_from(parsed)
end

#method_namesObject



35
36
37
# File 'lib/analyst/analyzer.rb', line 35

def method_names
  @method_names ||= method_names_from(parsed)
end

#methodsObject



27
28
29
# File 'lib/analyst/analyzer.rb', line 27

def methods
  @methods ||= methods_from(parsed)
end