Class: MetricsGeneratorCsv

Inherits:
Object
  • Object
show all
Includes:
DateUtil
Defined in:
lib/codespicuous/metrics_generator_csv.rb

Instance Method Summary collapse

Methods included from DateUtil

#begin_of_week, #for_each_week, #string_date

Constructor Details

#initialize(commit_history) ⇒ MetricsGeneratorCsv

Returns a new instance of MetricsGeneratorCsv.



7
8
9
# File 'lib/codespicuous/metrics_generator_csv.rb', line 7

def initialize(commit_history)
  @commit_history = commit_history
end

Instance Method Details

#create_commit_table_row_for_committer_with_repository_info(committer) ⇒ Object



15
16
17
18
# File 'lib/codespicuous/metrics_generator_csv.rb', line 15

def create_commit_table_row_for_committer_with_repository_info committer
  [committer.username, committer.team.name, @commit_history.repository_names.map { |repository|
    committer.amount_of_commits_to_repository(repository)}, committer.amount_of_commits].flatten
end

#create_commit_table_rows_with_committers_and_repository_info(team_to_select) ⇒ Object



20
21
22
23
# File 'lib/codespicuous/metrics_generator_csv.rb', line 20

def create_commit_table_rows_with_committers_and_repository_info(team_to_select)
  @commit_history.team(team_to_select.name).members.map { |committer|
    create_commit_table_row_for_committer_with_repository_info(committer) }
end

#create_commit_table_with_committers_and_repository_infoObject



25
26
27
28
29
30
31
32
# File 'lib/codespicuous/metrics_generator_csv.rb', line 25

def create_commit_table_with_committers_and_repository_info
  CSV.generate do |csv|
    csv << ["Committer", "Team", @commit_history.repository_names, "Total"].flatten
    @commit_history.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_infoObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/codespicuous/metrics_generator_csv.rb', line 45

def create_commit_table_with_week_and_repository_info
  CSV.generate do |csv|
    csv <<  ["Week", @commit_history.repository_names].flatten
    for_each_week(@commit_history.earliest_commit_date, @commit_history.latest_commit_date) { |week|
      csv << [string_date(week), @commit_history.repositories.map { |repository|
        repository.amount_of_commits_in_week(week)
      } ].flatten
    }
  end
end

#create_commit_table_with_weeks_and_committers(team = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/codespicuous/metrics_generator_csv.rb', line 56

def create_commit_table_with_weeks_and_committers(team=nil)
  CSV.generate do |csv|
    csv <<  ["Week", @commit_history.teams.member_usernames(team) ].flatten
    for_each_week(@commit_history.earliest_commit_date, @commit_history.latest_commit_date) { |week|
      csv <<  [string_date(week), @commit_history.teams.member_usernames(team).map { |name|
        @commit_history.committers.find_by_username(name).amount_of_commits_in_week(week)
      }].flatten
    }
  end
end

#create_commit_table_with_weeks_and_team_commitsObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/codespicuous/metrics_generator_csv.rb', line 34

def create_commit_table_with_weeks_and_team_commits
  CSV.generate do |csv|
    csv <<  ["Week", @commit_history.teams.team_names].flatten
    for_each_week(@commit_history.earliest_commit_date, @commit_history.latest_commit_date) { |week|
      csv << [string_date(week), @commit_history.teams.map { |team|
        @commit_history.amount_of_commits_for_team_in_week(team.name, week)
      } ].flatten
    }
  end
end

#generateObject



11
12
13
# File 'lib/codespicuous/metrics_generator_csv.rb', line 11

def generate

end