class Git::Log::Commit

Attributes

author[R]
date[R]
hash[R]
merge[R]
message[R]

Public Class Methods

new(values = {}) click to toggle source
# File lib/Git/Log.rb, line 66
def initialize(values = {})
  @hash = values[:hash]
  @merge = values[:merge]
  @author = values[:author]
  @date = values[:date]
  @message = values[:message]
end
parse(commit_string) click to toggle source
# File lib/Git/Log.rb, line 29
def parse(commit_string)
  hash = merge = author = date = message = ''
  commit_string.split("\n").each do |line|
    case line.strip
    when /^commit (\w+)/
      hash = line.strip.capture(/^commit (\w+)/)
    when /^Merge: /
      merge = line.strip.gsub(/^Merge: /, '')
    when /^Author: /
      author = line.strip.gsub(/^Author: /, '')
    when /^Date:   /
      date = line.strip.gsub(/^Date:   /, '')
    else
      if line.strip.empty?
        (message ||= '') << "\n\n"
      else
        (message ||= '') << line.lstrip
      end
    end
  end
  commit_args = {
    hash: hash,
    author: author,
    date: date,
    message: message.lstrip
  }
  commit_args.merge!(merge: merge)
  Commit.new(commit_args)
end