Class: Grit::GitRuby::UserInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/grit/git-ruby/object.rb,
lib/grit/git-ruby/git_object.rb

Overview

class for author/committer/tagger lines

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ UserInfo

Returns a new instance of UserInfo.


23
24
25
26
27
28
29
30
31
32
# File 'lib/grit/git-ruby/object.rb', line 23

def initialize(str)
  m = /^(.*?) <(.*)> (\d+) ([+-])0*(\d+?)$/.match(str)
  if !m
    raise RuntimeError, "invalid header '%s' in commit" % str
  end
  @name = m[1]
  @email = m[2]
  @date = Time.at(Integer(m[3]))
  @offset = (m[4] == "-" ? -1 : 1)*Integer(m[5])
end

Instance Attribute Details

#dateObject

Returns the value of attribute date


21
22
23
# File 'lib/grit/git-ruby/object.rb', line 21

def date
  @date
end

#emailObject

Returns the value of attribute email


21
22
23
# File 'lib/grit/git-ruby/object.rb', line 21

def email
  @email
end

#nameObject

Returns the value of attribute name


21
22
23
# File 'lib/grit/git-ruby/object.rb', line 21

def name
  @name
end

#offsetObject

Returns the value of attribute offset


21
22
23
# File 'lib/grit/git-ruby/object.rb', line 21

def offset
  @offset
end

Instance Method Details

#to_sObject


34
35
36
# File 'lib/grit/git-ruby/object.rb', line 34

def to_s
  "%s <%s> %s %+05d" % [@name, @email, @date.to_i, @offset]
end