git-timecost/lib/timecost/author_list.rb

35 lines
638 B
Ruby
Raw Normal View History

2014-09-24 18:11:05 +00:00
2014-09-25 06:05:05 +00:00
require 'pp'
2014-09-24 18:11:05 +00:00
module TimeCost
class AuthorList
2014-09-25 06:05:05 +00:00
class UnknownAuthor < RuntimeError ; end
2014-09-24 18:11:05 +00:00
# Prepare an empty index (local)
def initialize
@count = 0
2014-09-25 06:05:05 +00:00
@author_to_id = {}
2014-09-24 18:11:05 +00:00
end
2014-09-25 06:05:05 +00:00
def add author
if @author_to_id.include? author then
result = @author_to_id[author]
2014-09-24 18:11:05 +00:00
else
2014-09-25 06:05:05 +00:00
@author_to_id[author] = @count
2014-09-24 18:11:05 +00:00
result = @count
@count += 1
end
end
2014-09-25 06:05:05 +00:00
def alias author_ref, author_new
raise UnknownAuthor unless @author_to_id.include? author_ref
end
# Return local user id for git user
# FIXME: should handle multiple names for same user
def parse author
return @author_to_id[author]
end
2014-09-24 18:11:05 +00:00
end
end