Class: Grit::GitRuby::UserInfo

Inherits:
Object
  • Object
show all
Defined in:
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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/grit/git-ruby/git_object.rb', line 23

def initialize(str)
  @email = ''
  @date = Time.now
  @offset = 0

  m = /^(.*?) <(.*)> (\d+) ([+-])0*(\d+?)$/.match(str)
  if !m
    case str
    when /<.+>/
      m, @name, @email = *str.match(/(.*) <(.+?)>/)
    else
      @name = str
    end
  else
    @name = m[1]
    @email = m[2]
    @date = Time.at(Integer(m[3]))
    @offset = (m[4] == "-" ? -1 : 1)*Integer(m[5])
  end
end

Instance Attribute Details

#dateObject

Returns the value of attribute date



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

def date
  @date
end

#emailObject

Returns the value of attribute email



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

def email
  @email
end

#nameObject

Returns the value of attribute name



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

def name
  @name
end

#offsetObject

Returns the value of attribute offset



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

def offset
  @offset
end

Instance Method Details

#to_sObject



44
45
46
# File 'lib/grit/git-ruby/git_object.rb', line 44

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