Class: Codeowners::Git::Contributors
- Inherits:
-
Object
- Object
- Codeowners::Git::Contributors
- Defined in:
- lib/codeowners/git/contributors.rb
Class Method Summary collapse
- .calculate_stats(stats) ⇒ Object
-
.call(file, output) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
.each_commit(lines) ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize.
- .extract_authors(authors) ⇒ Object
- .parse(commit) ⇒ Object
- .scan(string, pattern) ⇒ Object
Instance Method Summary collapse
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(data) ⇒ Contributors
constructor
A new instance of Contributors.
Constructor Details
#initialize(data) ⇒ Contributors
Returns a new instance of Contributors.
72 73 74 75 76 |
# File 'lib/codeowners/git/contributors.rb', line 72 def initialize(data) @contributors = data.map do |email, stats| Contributor.new(email, *stats.values) end end |
Class Method Details
.calculate_stats(stats) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/codeowners/git/contributors.rb', line 58 def self.calculate_stats(stats) stats.each_with_object([0, 0]) do |stat, result| stat = stat.split(/[[:space:]]+/) insertions, deletions, = *stat result[0] += Integer(insertions) result[1] += Integer(deletions) end end |
.call(file, output) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/codeowners/git/contributors.rb', line 11 def self.call(file, output) lines = output.split($INPUT_RECORD_SEPARATOR) result = {} each_commit(lines) do |, insertions, deletions| .each do || = .fetch("email") = .fetch("name") result[] ||= {} result[]["name"] = result[]["file"] = file result[]["insertions"] ||= 0 result[]["deletions"] ||= 0 result[]["insertions"] += insertions result[]["deletions"] += deletions end end new(result) end |
.each_commit(lines) ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize
35 36 37 38 39 40 41 |
# File 'lib/codeowners/git/contributors.rb', line 35 def self.each_commit(lines) while lines.any? commit = lines.take_while { |line| line != "" } yield parse(commit.dup) unless commit.empty? lines.shift(commit.size + 1) end end |
.extract_authors(authors) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/codeowners/git/contributors.rb', line 49 def self.() .map do || { "name" => scan(, /author:(.*)email:/).chop, "email" => scan(, /email:(.*)/) } end.uniq end |
.parse(commit) ⇒ Object
43 44 45 46 47 |
# File 'lib/codeowners/git/contributors.rb', line 43 def self.parse(commit) , stats = commit.partition { |line| line.match?(/author:/) } [(), *calculate_stats(stats)] end |
.scan(string, pattern) ⇒ Object
68 69 70 |
# File 'lib/codeowners/git/contributors.rb', line 68 def self.scan(string, pattern) string.scan(pattern).flatten.first end |
Instance Method Details
#each(&blk) ⇒ Object
78 79 80 81 82 |
# File 'lib/codeowners/git/contributors.rb', line 78 def each(&blk) return enum_for(:each) unless block_given? @contributors.each(&blk) end |
#empty? ⇒ Boolean
84 85 86 |
# File 'lib/codeowners/git/contributors.rb', line 84 def empty? @contributors.empty? end |