mirror of
https://github.com/tomgi/git_stats.git
synced 2024-12-22 13:32:17 +01:00
activity creation dryed out
This commit is contained in:
parent
dd228a4dd4
commit
72944cc5c5
3 changed files with 20 additions and 19 deletions
|
@ -2,17 +2,10 @@ module GitStats
|
|||
module GitData
|
||||
class Activity
|
||||
|
||||
def add_commit(commit)
|
||||
add_commit_at(commit.date)
|
||||
end
|
||||
|
||||
def add_commit_at(date)
|
||||
self.by_hour[date.hour] += 1
|
||||
self.by_wday[date.wday] += 1
|
||||
self.by_wday_hour[date.wday][date.hour] += 1
|
||||
self.by_month[date.month] += 1
|
||||
self.by_year[date.year] += 1
|
||||
self.by_year_week[date.year][date.cweek] += 1
|
||||
def initialize(commits)
|
||||
commits.values.each do |commit|
|
||||
add_commit(commit)
|
||||
end
|
||||
end
|
||||
|
||||
def by_hour
|
||||
|
@ -39,6 +32,20 @@ module GitStats
|
|||
@by_year_week ||= Hash.new { |h, k| h[k] = Hash.new(0) }
|
||||
end
|
||||
|
||||
private
|
||||
def add_commit(commit)
|
||||
add_commit_at(commit.date)
|
||||
end
|
||||
|
||||
def add_commit_at(date)
|
||||
self.by_hour[date.hour] += 1
|
||||
self.by_wday[date.wday] += 1
|
||||
self.by_wday_hour[date.wday][date.hour] += 1
|
||||
self.by_month[date.month] += 1
|
||||
self.by_year[date.year] += 1
|
||||
self.by_year_week[date.year][date.cweek] += 1
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -17,10 +17,7 @@ module GitStats
|
|||
end
|
||||
|
||||
def activity
|
||||
@activity ||= commits.values.inject(Activity.new) do |activity, commit|
|
||||
activity.add_commit(commit)
|
||||
activity
|
||||
end
|
||||
@activity ||= Activity.new(commits)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -27,10 +27,7 @@ module GitStats
|
|||
end
|
||||
|
||||
def activity
|
||||
@activity ||= commits.values.inject(Activity.new) do |activity, commit|
|
||||
activity.add_commit(commit)
|
||||
activity
|
||||
end
|
||||
@activity ||= Activity.new(commits)
|
||||
end
|
||||
|
||||
def project_version
|
||||
|
|
Loading…
Reference in a new issue