Class: CommitStatistics
- Inherits:
-
Object
- Object
- CommitStatistics
- Defined in:
- lib/codespicuous/commitstatistics.rb
Instance Attribute Summary collapse
-
#committer_statistics ⇒ Object
Returns the value of attribute committer_statistics.
Instance Method Summary collapse
- #amount_of_comitters ⇒ Object
- #amount_of_commits_for_team_in_week(team, week) ⇒ Object
- #amount_of_commits_to_repository_in_week(repository, week) ⇒ Object
- #commit(username, repository, date) ⇒ Object
- #commits=(commits) ⇒ Object
- #committer(username) ⇒ Object
- #committer_in_team(team) ⇒ Object
- #create_commit_table_row_for_committer_with_repository_info(committer) ⇒ Object
- #create_commit_table_rows_with_committers_and_repository_info(team_to_select) ⇒ Object
- #create_commit_table_with_committers_and_repository_info ⇒ Object
- #create_commit_table_with_week_and_repository_info ⇒ Object
- #create_commit_table_with_weeks_and_committers(team = nil) ⇒ Object
- #create_commit_table_with_weeks_and_team_commits ⇒ Object
- #first_week_committed ⇒ Object
- #for_each_week ⇒ Object
-
#initialize ⇒ CommitStatistics
constructor
A new instance of CommitStatistics.
- #last_week_committed ⇒ Object
- #repositories_committed_to ⇒ Object
- #string_date(date) ⇒ Object
- #teams ⇒ Object
- #teams=(teams) ⇒ Object
Constructor Details
#initialize ⇒ CommitStatistics
Returns a new instance of CommitStatistics.
111 112 113 |
# File 'lib/codespicuous/commitstatistics.rb', line 111 def initialize self.committer_statistics = {} end |
Instance Attribute Details
#committer_statistics ⇒ Object
Returns the value of attribute committer_statistics.
109 110 111 |
# File 'lib/codespicuous/commitstatistics.rb', line 109 def committer_statistics @committer_statistics end |
Instance Method Details
#amount_of_comitters ⇒ Object
175 176 177 |
# File 'lib/codespicuous/commitstatistics.rb', line 175 def amount_of_comitters self.committer_statistics.size end |
#amount_of_commits_for_team_in_week(team, week) ⇒ Object
179 180 181 182 183 |
# File 'lib/codespicuous/commitstatistics.rb', line 179 def amount_of_commits_for_team_in_week(team, week) @committer_statistics.each_value.inject(0) { |amount_of_commits, committer| amount_of_commits + ((committer.team == team) ? committer.amount_of_commits_in_week(week) : 0) } end |
#amount_of_commits_to_repository_in_week(repository, week) ⇒ Object
185 186 187 188 189 |
# File 'lib/codespicuous/commitstatistics.rb', line 185 def amount_of_commits_to_repository_in_week(repository, week) @committer_statistics.each_value.inject(0) { |amount_of_commits, committer| amount_of_commits + committer.amount_of_commits_to_repository_in_week(repository, week) } end |
#commit(username, repository, date) ⇒ Object
127 128 129 |
# File 'lib/codespicuous/commitstatistics.rb', line 127 def commit(username, repository, date) committer(username).commit(repository, date, 1) end |
#commits=(commits) ⇒ Object
115 116 117 118 119 |
# File 'lib/codespicuous/commitstatistics.rb', line 115 def commits= commits commits.each { |commit| commit(commit., commit.repository, commit.date) } end |
#committer(username) ⇒ Object
131 132 133 |
# File 'lib/codespicuous/commitstatistics.rb', line 131 def committer username @committer_statistics[username] ||= CommitStatisticsForCommitter.new(username) end |
#committer_in_team(team) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/codespicuous/commitstatistics.rb', line 135 def committer_in_team(team) team_members = [] @committer_statistics.each_value { |committer| team_members << committer.username if committer.team == team || team == nil } team_members end |
#create_commit_table_row_for_committer_with_repository_info(committer) ⇒ Object
201 202 203 |
# File 'lib/codespicuous/commitstatistics.rb', line 201 def create_commit_table_row_for_committer_with_repository_info committer [committer.username, committer.team, repositories_committed_to.map { |repository| committer.amount_of_comnmits_to_repository(repository)}, committer.amount_of_commits].flatten end |
#create_commit_table_rows_with_committers_and_repository_info(team_to_select) ⇒ Object
205 206 207 |
# File 'lib/codespicuous/commitstatistics.rb', line 205 def create_commit_table_rows_with_committers_and_repository_info(team_to_select) @committer_statistics.values.select { |committer| committer.team == team_to_select }.map { |committer| create_commit_table_row_for_committer_with_repository_info(committer) } end |
#create_commit_table_with_committers_and_repository_info ⇒ Object
209 210 211 212 213 214 215 216 |
# File 'lib/codespicuous/commitstatistics.rb', line 209 def create_commit_table_with_committers_and_repository_info CSV.generate do |csv| csv << ["Committer", "Team", repositories_committed_to, "Total"].flatten teams.each { |team| create_commit_table_rows_with_committers_and_repository_info(team).each { |row| csv << row } } end end |
#create_commit_table_with_week_and_repository_info ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/codespicuous/commitstatistics.rb', line 227 def create_commit_table_with_week_and_repository_info CSV.generate do |csv| csv << ["Week", repositories_committed_to].flatten for_each_week { |week| csv << [string_date(week), repositories_committed_to.map { |repository| amount_of_commits_to_repository_in_week(repository, week) } ].flatten } end end |
#create_commit_table_with_weeks_and_committers(team = nil) ⇒ Object
236 237 238 239 240 241 242 243 |
# File 'lib/codespicuous/commitstatistics.rb', line 236 def create_commit_table_with_weeks_and_committers(team=nil) CSV.generate do |csv| csv << ["Week", committer_in_team(team) ].flatten for_each_week { |week| csv << [string_date(week), @committer_statistics.values.select { |committer| committer.team == team || team == nil }.map { |committer| committer.amount_of_commits_in_week(week)} ].flatten } end end |
#create_commit_table_with_weeks_and_team_commits ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/codespicuous/commitstatistics.rb', line 218 def create_commit_table_with_weeks_and_team_commits CSV.generate do |csv| csv << ["Week", teams].flatten for_each_week { |week| csv << [string_date(week), teams.map { |team| amount_of_commits_for_team_in_week(team, week) } ].flatten } end end |
#first_week_committed ⇒ Object
159 160 161 162 163 164 165 |
# File 'lib/codespicuous/commitstatistics.rb', line 159 def first_week_committed commit_week = DateTime.now @committer_statistics.each_value { |committer| commit_week = committer.first_week_committed if committer.first_week_committed < commit_week } commit_week end |
#for_each_week ⇒ Object
191 192 193 194 195 |
# File 'lib/codespicuous/commitstatistics.rb', line 191 def for_each_week (first_week_committed..last_week_committed).step(7) { |week| yield week } end |
#last_week_committed ⇒ Object
167 168 169 170 171 172 173 |
# File 'lib/codespicuous/commitstatistics.rb', line 167 def last_week_committed commit_week = DateTime.new(1977) @committer_statistics.each_value { |committer| commit_week = committer.last_week_committed if committer.last_week_committed > commit_week } commit_week end |
#repositories_committed_to ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/codespicuous/commitstatistics.rb', line 143 def repositories_committed_to names = [] @committer_statistics.each_value { |stats_for_committer| names << stats_for_committer.repositories_committed_to } names.flatten.uniq end |
#string_date(date) ⇒ Object
197 198 199 |
# File 'lib/codespicuous/commitstatistics.rb', line 197 def string_date(date) date.strftime("%Y-%m-%d") end |
#teams ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/codespicuous/commitstatistics.rb', line 151 def teams teams = [] @committer_statistics.each_value { |stats_for_committer| teams << stats_for_committer.team } teams.flatten.uniq.sort end |
#teams=(teams) ⇒ Object
121 122 123 124 125 |
# File 'lib/codespicuous/commitstatistics.rb', line 121 def teams= teams teams.each_member { |team, member| committer(member.username).team = team.name } end |