Class: DependencyAnalyzer

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

Instance Method Summary collapse

Constructor Details

#initializeDependencyAnalyzer

Returns a new instance of DependencyAnalyzer.



4
5
6
7
# File 'lib/dependency_analyzer.rb', line 4

def initialize
  @graph = Courgette::DirectoryAnalyser.new.tap { |da| da.analyse('**/*.rb') }.graph
  @stats = @graph.nodes.map { |node| { :in => @graph.dependency_count(node), :out => @graph.depender_count(node), :name => node.join("::") } }
end

Instance Method Details

#get_in_stats(n) ⇒ Object



9
10
11
# File 'lib/dependency_analyzer.rb', line 9

def get_in_stats(n)
  get_stats(maybe_take(@stats.sort { |a, b| b[:in] <=> a[:in] }, n), :in)
end

#get_out_stats(n) ⇒ Object



13
14
15
# File 'lib/dependency_analyzer.rb', line 13

def get_out_stats(n)
  get_stats(maybe_take(@stats.sort { |a, b| b[:out] <=> a[:out] }, n), :out)
end

#get_stats(stat_array, stat_index) ⇒ Object



17
18
19
# File 'lib/dependency_analyzer.rb', line 17

def get_stats(stat_array, stat_index)
  stat_array.map { |x| "#{x[stat_index]} #{x[:name]}" }.join("\n")
end