Sha256: 2bc1ff1862ef775c4d82594fde29e7cf881c724475f744e470abc849c5eebb5f

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 Bytes

Contents

require 'date'

module PairingMatrix
  class CommitReader
    def initialize(config)
        @config = config
    end

    def authors_with_commits(days)
        date = (Date.today - days).to_s
        authors = authors(date)
        author_groups = authors.group_by { |n| titleize(n)}
        author_groups.map do |k, v|
            pair = k.split(',')
            pair.unshift('') if pair.size == 1
            [pair, v.size].flatten
        end
    end

    protected
    def read(since)
        #to be implemented by child commit reader
    end

    private
    def authors(since)
        commits = if @config.absent? then [] else read(since) end
        commits.map do |commit|
          commit.scan(/#{@config.authors_regex}/).flatten.compact.reject(&:empty?).map { |name| name.gsub(' ', '') }.sort.join(',')
        end.compact.reject(&:empty?)
    end

    def titleize(name)
        name.gsub(/\w+/) do |word|
            word.capitalize
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pairing_matrix-3.0.0 lib/pairing_matrix/commit_readers/commit_reader.rb