Class: Twigg::CommitSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Decoratable
Defined in:
lib/twigg/commit_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Decoratable

#decorate

Constructor Details

#initialize(commits = []) ⇒ CommitSet

Returns a new instance of CommitSet.



11
12
13
# File 'lib/twigg/commit_set.rb', line 11

def initialize(commits = [])
  @commits = commits
end

Instance Attribute Details

#commitsObject (readonly)

Returns the value of attribute commits.



9
10
11
# File 'lib/twigg/commit_set.rb', line 9

def commits
  @commits
end

Instance Method Details

#+(commit_set) ⇒ Object

Returns a copy of the receiver merged with ‘commit_set`.



49
50
51
52
53
54
55
56
57
58
# 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

#additionsObject



15
16
17
18
19
# File 'lib/twigg/commit_set.rb', line 15

def additions
  @additions ||= inject(0) do |memo, commit|
    memo + commit.stat[:additions]
  end
end

#authorsObject



85
86
87
88
89
# File 'lib/twigg/commit_set.rb', line 85

def authors
  @authors ||= author_to_commit_set.
    sort_by { |author, commit_set| -commit_set.count }.
    map { |author, commit_set| { author: author, commit_set: commit_set } }
end

#count_by_day(days) ⇒ Object



39
40
41
42
43
44
45
46
# 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_repoObject



60
61
62
63
64
65
# 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

#deletionsObject



21
22
23
24
25
# File 'lib/twigg/commit_set.rb', line 21

def deletions
  @deletions ||= inject(0) do |memo, commit|
    memo + commit.stat[:deletions]
  end
end

#flesch_reading_easeObject



27
28
29
30
31
# 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

#pairsObject

Returns a sparse pairing “matrix”.

Keys are pairer names. Values are hashes of pairees-to-count maps.



94
95
96
# File 'lib/twigg/commit_set.rb', line 94

def pairs
  PairMatrix.new(self)
end

#russiannessObject



33
34
35
36
37
# File 'lib/twigg/commit_set.rb', line 33

def russianness
  @russianness ||= inject(0) do |memo, commit|
    memo + commit.russianness
  end
end

#select_author(author) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/twigg/commit_set.rb', line 67

def select_author(author)
  commits_for_author = @commits.select do |commit|
    commit.author_names.include?(author)
  end

  self.class.new(commits_for_author)
end

#select_team(team) ⇒ Object



75
76
77
78
79
80
81
82
83
# 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

#teamsObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# 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