class Twigg::CommitSet
Attributes
commits[R]
Public Class Methods
new(commits = [])
click to toggle source
# File lib/twigg/commit_set.rb, line 11 def initialize(commits = []) @commits = commits end
Public Instance Methods
+(commit_set)
click to toggle source
Returns a copy of the receiver merged with `commit_set`.
# File lib/twigg/commit_set.rb, line 49 def +(commit_set) unless commit_set.is_a?(CommitSet) raise TypeError, "expected Twigg::CommitSet, got #{commit_set.class}" end dup.tap do |other| other.commits.concat(commit_set.commits) other.commits.uniq! end end
additions()
click to toggle source
# File lib/twigg/commit_set.rb, line 15 def additions @additions ||= inject(0) do |memo, commit| memo + commit.stat[:additions] end end
count_by_day(days)
click to toggle source
# File lib/twigg/commit_set.rb, line 39 def count_by_day(days) start_date = Date.today - days end_date = Date.today date_to_commits = @commits.group_by { |commit| commit.date } (start_date..end_date).map do |date| { date: date, count: date_to_commits.fetch(date, []).count } end end
count_by_repo()
click to toggle source
# File lib/twigg/commit_set.rb, line 60 def count_by_repo counts = Hash.new(0) each { |commit| counts[commit.repo] += 1 } counts.sort_by { |repo, count| -count }. map { |repo, count| { repo: repo, count: count } } end
deletions()
click to toggle source
# File lib/twigg/commit_set.rb, line 21 def deletions @deletions ||= inject(0) do |memo, commit| memo + commit.stat[:deletions] end end
flesch_reading_ease()
click to toggle source
# File lib/twigg/commit_set.rb, line 27 def flesch_reading_ease @flesch_reading_ease ||= inject(0) do |memo, commit| memo + commit.flesch_reading_ease end / count end
pairs()
click to toggle source
Returns a sparse pairing “matrix”.
Keys are pairer names. Values are hashes of pairees-to-count maps.
# File lib/twigg/commit_set.rb, line 94 def pairs PairMatrix.new(self) end
russianness()
click to toggle source
# File lib/twigg/commit_set.rb, line 33 def russianness @russianness ||= inject(0) do |memo, commit| memo + commit.russianness end end
select_team(team)
click to toggle source
# File lib/twigg/commit_set.rb, line 75 def select_team(team) members = Set.new(Config.teams[team]) commits_for_team = @commits.select do |commit| commit.author_names.any? { |author| members.include?(author) } end self.class.new(commits_for_team) end
teams()
click to toggle source
# File lib/twigg/commit_set.rb, line 98 def teams set = author_to_commit_set teams = Config.teams.each_pair.map do |team, members| commits = members.each_with_object(self.class.new) do |member, commit_set| if member = set.delete(member) commit_set += member end end if commits.any? { author: team.to_s, commit_set: commits, authors: members, } end end.compact.sort_by { |team| -team[:commit_set].count } unless set.empty? teams << { author: Team::OTHER_TEAM_NAME, commit_set: set.values.inject(self.class.new, :+), authors: set.keys, } end teams end