Class: DependencyAnalyzer
- Inherits:
-
Object
- Object
- DependencyAnalyzer
- Defined in:
- lib/dependency_analyzer.rb
Instance Method Summary collapse
- #get_in_stats(n) ⇒ Object
- #get_out_stats(n) ⇒ Object
- #get_stats(stat_array, stat_index) ⇒ Object
-
#initialize ⇒ DependencyAnalyzer
constructor
A new instance of DependencyAnalyzer.
Constructor Details
#initialize ⇒ DependencyAnalyzer
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 |