Class: Hellgrid::Matrix
- Inherits:
-
Object
- Object
- Hellgrid::Matrix
- Defined in:
- lib/hellgrid/matrix.rb
Instance Attribute Summary collapse
-
#projects ⇒ Object
readonly
Returns the value of attribute projects.
Instance Method Summary collapse
- #add_project(project) ⇒ Object
- #gem_names ⇒ Object
- #gems_by_usage ⇒ Object
-
#initialize ⇒ Matrix
constructor
A new instance of Matrix.
- #project_names ⇒ Object
- #projects_sorted_by_name ⇒ Object
- #sorted_by_most_used ⇒ Object
Constructor Details
#initialize ⇒ Matrix
5 6 7 |
# File 'lib/hellgrid/matrix.rb', line 5 def initialize @projects = [] end |
Instance Attribute Details
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
3 4 5 |
# File 'lib/hellgrid/matrix.rb', line 3 def projects @projects end |
Instance Method Details
#add_project(project) ⇒ Object
9 10 11 |
# File 'lib/hellgrid/matrix.rb', line 9 def add_project(project) @projects << project end |
#gem_names ⇒ Object
21 22 23 |
# File 'lib/hellgrid/matrix.rb', line 21 def gem_names @projects.map { |p| p.dependency_matrix.keys }.flatten.uniq end |
#gems_by_usage ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/hellgrid/matrix.rb', line 35 def gems_by_usage gem_usage = Hash.new(0) projects.each do |project| project.dependency_matrix.each do |gem, _| gem_usage[gem] += 1 end end gem_usage.sort_by {|key, value| [-value, key] }.to_h end |
#project_names ⇒ Object
17 18 19 |
# File 'lib/hellgrid/matrix.rb', line 17 def project_names projects_sorted_by_name.map(&:name) end |
#projects_sorted_by_name ⇒ Object
13 14 15 |
# File 'lib/hellgrid/matrix.rb', line 13 def projects_sorted_by_name @projects.sort { |a,b| a.name <=> b.name } end |
#sorted_by_most_used ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/hellgrid/matrix.rb', line 25 def sorted_by_most_used header = [nil] + project_names body = gems_by_usage.keys.map do |gem| [gem] + projects_sorted_by_name.map { |project| project.dependency_matrix[gem] } end [header] + body end |