activity creation dryed out

This commit is contained in:
Tomasz Gieniusz 2012-10-12 18:24:28 +02:00
parent dd228a4dd4
commit 72944cc5c5
3 changed files with 20 additions and 19 deletions

View file

@ -2,17 +2,10 @@ module GitStats
module GitData
class Activity
def add_commit(commit)
add_commit_at(commit.date)
def initialize(commits)
commits.values.each do |commit|
add_commit(commit)
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
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

View file

@ -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

View file

@ -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