This commit is contained in:
Tomasz Gieniusz 2012-10-21 23:11:37 +02:00
parent 7ac6dcb6c4
commit ff62823dd2
5 changed files with 21 additions and 39 deletions

View file

@ -29,7 +29,7 @@ module GitStats
@files_by_extension_count ||= Hash[files_by_extension.map { |ext, files| [ext, files.count] }]
end
def lines_by_extension
def lines_by_extension_count
@lines_by_extension ||= Hash[files_by_extension.map { |ext, files|
[ext, files.map(&:lines_count).sum]
}.delete_if { |ext, lines_count| lines_count == 0 }]

View file

@ -7,7 +7,7 @@ module GitStats
attr_reader :path
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension,
delegate :files, :files_by_extension, :files_by_extension_count, :lines_by_extension_count,
:files_count, :binary_files, :text_files, :lines_count, to: :last_commit
def initialize(params)

View file

@ -6,44 +6,26 @@ module GitStats
@repo = repo
end
def files_by_extension
[:lines, :files].each do |type|
define_method "#{type}_by_extension" do
Chart.new do |f|
f.column_hash_chart(
data: @repo.files_by_extension_count,
title: :files_by_extension.t,
y_text: :files.t
data: @repo.send("#{type}_by_extension_count"),
title: "#{type}_extension".to_sym.t,
y_text: type.to_sym.t
)
end
end
def lines_by_extension
Chart.new do |f|
f.column_hash_chart(
data: @repo.lines_by_extension,
title: :lines_by_extension.t,
y_text: :lines.t
)
end
end
def files_by_date
define_method "#{type}_by_date" do
Chart.new do |f|
f.date_chart(
data: @repo.files_count_by_date,
title: :files_by_date.t,
y_text: :files.t
data: @repo.send("#{type}_count_by_date"),
title: "#{type}_by_date".to_sym.t,
y_text: type.to_sym.t
)
end
end
def lines_by_date
Chart.new do |f|
f.date_chart(
data: @repo.lines_count_by_date,
title: :lines_by_date.t,
y_text: :lines.t
)
end
end
[:commits_count_by_author, :insertions_by_author, :deletions_by_author].each do |method|

View file

@ -40,7 +40,7 @@ describe GitStats::GitData::Commit do
double(lines_count: 0, extension: '.haml'),
double(lines_count: 20, extension: '.css'),
)
commit.lines_by_extension.should == {'.rb' => 100, '.css' => 20}
commit.lines_by_extension_count.should == {'.rb' => 100, '.css' => 20}
end
end
end

View file

@ -46,7 +46,7 @@ describe GitStats::GitData::Repo do
end
it 'should count lines by extension in repo' do
repo.lines_by_extension.should == {'.haml' => 100, '.txt' => 1008, '.rb' => 6}
repo.lines_by_extension_count.should == {'.haml' => 100, '.txt' => 1008, '.rb' => 6}
end
it 'should count commits_count_by_author' do