activity creation dryed out

This commit is contained in:
Tomasz Gieniusz 2012-10-12 18:30:07 +02:00
parent 72944cc5c5
commit 00e99ea4af
2 changed files with 10 additions and 29 deletions

View file

@ -10,6 +10,6 @@ require "git_stats/cli"
begin
cli = GitStats::CLI.new
cli.start(*ARGV)
rescue => e
rescue ArgumentError => e
puts e.message
end

View file

@ -2,39 +2,20 @@ module GitStats
module GitData
class Activity
attr_reader :by_hour, :by_wday, :by_wday_hour, :by_month, :by_year, :by_year_week
def initialize(commits)
commits.values.each do |commit|
add_commit(commit)
end
end
@by_hour = @by_wday = @by_month = @by_year = Hash.new(0)
@by_wday_hour = @by_year_week = Hash.new { |h, k| h[k] = Hash.new(0) }
def by_hour
@by_hour ||= Hash.new(0)
end
def by_wday
@by_wday ||= Hash.new(0)
end
def by_wday_hour
@by_wday_hour ||= Hash.new { |h, k| h[k] = Hash.new(0) }
end
def by_month
@by_month ||= Hash.new(0)
end
def by_year
@by_year ||= Hash.new(0)
end
def by_year_week
@by_year_week ||= Hash.new { |h, k| h[k] = Hash.new(0) }
add_commits(commits)
end
private
def add_commit(commit)
add_commit_at(commit.date)
def add_commits(commits)
commits.values.each do |commit|
add_commit_at(commit.date)
end
end
def add_commit_at(date)