class Ginbeer

Constants

VERSION

Public Class Methods

new(dir, from="", to=Time.now) click to toggle source
# File lib/ginbeer/ginbeer.rb, line 5
def initialize(dir, from="", to=Time.now)
  @dir = dir
  @from = from
  @from_d = nil
  if @from != ""
    @from_d = Time.parse(@from)
  end
  @to = to


  # error handling
  epath = File.expand_path(dir)
  if File.exist?(File.join(epath, '.git'))
  elsif File.exist?(epath) && (epath =~ /\.git$/)
  elsif File.exist?(epath)
    raise InvalidGitRepositoryError.new(epath)
  else
    raise NoSuchPathError.new(epath)
  end
end

Public Instance Methods

authors() click to toggle source
# File lib/ginbeer/ginbeer.rb, line 26
def authors
  authors = []
  commits = `#{self.shortlog_command}` 
  commits.each_line do |line|
    line.chomp!
    /\s*(\d+)\s(.+)/ =~ line

    count = $1.to_i
    name = $2
    authors.push(Author.new(name, count))
  end

  authors.each do |author|
    logs = `#{self.log_command(author)}`

    logs.each_line do |line|
      line.chomp!
      if /file/ =~ line
        /.*(\d+) insertion.*, (\d+) deletion/ =~ line
        insertion = $1.to_i
        deletion = $2.to_i

        author.insertion += insertion
        author.deletion += deletion
      elsif /\[(.+)\]/ =~ line
        data = $1 
        data = Time.parse(data)
        break if @from_d != nil && data < @from_d # 終了
      end
    end
  end
  return authors
end
cd_command() click to toggle source
# File lib/ginbeer/ginbeer.rb, line 60
def cd_command
  return "cd #{@dir} &&"
end
log_command(author) click to toggle source
# File lib/ginbeer/ginbeer.rb, line 70
def log_command(author)
  command = "#{self.cd_command} git log --pretty=format:'[%ad]' --shortstat --author='#{author.name}' --date=short --before=#{@to}"
  return command
end
shortlog_command() click to toggle source
# File lib/ginbeer/ginbeer.rb, line 64
def shortlog_command
  command = "#{self.cd_command} git shortlog -s --no-merges -n --before=#{@to}"
  command += " --after=#{@from}" if @from != ""
  return command
end