class JekyllGitAuthors::Git::Log

Git::Log parses output passed from Git#log and creates a hash with author as a key and email as value

Public Class Methods

new(log, max_authors_count = 5) click to toggle source

We are expecting output from “git log” command max_authors_count - maximum number of unique authors to return

# File lib/jekyll-git-authors/git.rb, line 10
def initialize(log, max_authors_count = 5)
  @log = log.force_encoding(Encoding::UTF_8)
  @max_authors_count = max_authors_count

  raise InvalidEncoding unless @log.valid_encoding?
end

Public Instance Methods

authors() click to toggle source

Create array of unique authors and return maximum specified by @max_authors_count.

# File lib/jekyll-git-authors/git.rb, line 18
def authors
  @log.each_line
    .map { |author| author.strip.split(';') }
    .map { |name, email| JekyllGitAuthors::Author.new name, email }
    .uniq { |author| author[:name] }
    .take @max_authors_count
end
to_s() click to toggle source

To ensure log will be text when we want

# File lib/jekyll-git-authors/git.rb, line 27
def to_s
  @log
end