Class: Twigg::CommitSet
- Inherits:
-
Object
- Object
- Twigg::CommitSet
- Extended by:
- Forwardable
- Includes:
- Decoratable
- Defined in:
- lib/twigg/commit_set.rb
Instance Attribute Summary collapse
-
#commits ⇒ Object
readonly
Returns the value of attribute commits.
Instance Method Summary collapse
-
#+(commit_set) ⇒ Object
Returns a copy of the receiver merged with ‘commit_set`.
- #additions ⇒ Object
- #authors ⇒ Object
- #count_by_day(days) ⇒ Object
- #count_by_repo ⇒ Object
- #deletions ⇒ Object
- #flesch_reading_ease ⇒ Object
-
#initialize(commits = []) ⇒ CommitSet
constructor
A new instance of CommitSet.
-
#pairs ⇒ Object
Returns a sparse pairing “matrix”.
- #russianness ⇒ Object
- #select_author(author) ⇒ Object
- #select_team(team) ⇒ Object
- #teams ⇒ Object
Methods included from Decoratable
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
#commits ⇒ Object (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 |
#additions ⇒ Object
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 |
#authors ⇒ Object
85 86 87 88 89 |
# File 'lib/twigg/commit_set.rb', line 85 def @authors ||= . sort_by { |, commit_set| -commit_set.count }. map { |, commit_set| { 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_repo ⇒ Object
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 |
#deletions ⇒ Object
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_ease ⇒ Object
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 |
#pairs ⇒ Object
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 |
#russianness ⇒ Object
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 () = @commits.select do |commit| commit..include?() end self.class.new() 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..any? { || members.include?() } end self.class.new(commits_for_team) end |
#teams ⇒ Object
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 = 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 |