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
Returns a new instance of Matrix.
7 8 9 |
# File 'lib/hellgrid/matrix.rb', line 7 def initialize @projects = [] end |
Instance Attribute Details
#projects ⇒ Object (readonly)
Returns the value of attribute projects.
5 6 7 |
# File 'lib/hellgrid/matrix.rb', line 5 def projects @projects end |
Instance Method Details
#add_project(project) ⇒ Object
11 12 13 |
# File 'lib/hellgrid/matrix.rb', line 11 def add_project(project) @projects << project end |
#gem_names ⇒ Object
23 24 25 |
# File 'lib/hellgrid/matrix.rb', line 23 def gem_names @projects.map { |p| p.dependency_matrix.keys }.flatten.uniq end |
#gems_by_usage ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hellgrid/matrix.rb', line 37 def gems_by_usage gem_usage = Hash.new(0) projects.each do |project| project.dependency_matrix.each_key do |gem| gem_usage[gem] += 1 end end gem_usage.sort_by { |key, value| [-value, key] }.to_h end |
#project_names ⇒ Object
19 20 21 |
# File 'lib/hellgrid/matrix.rb', line 19 def project_names projects_sorted_by_name.map(&:name) end |
#projects_sorted_by_name ⇒ Object
15 16 17 |
# File 'lib/hellgrid/matrix.rb', line 15 def projects_sorted_by_name @projects.sort { |a, b| a.name <=> b.name } end |
#sorted_by_most_used ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/hellgrid/matrix.rb', line 27 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 |