Parent

Files

Grit::Actor

Attributes

email[R]
name[R]
to_s[R]

Public Class Methods

from_string(str) click to toggle source

Create an Actor from a string.

str - The String in this format: ‘John Doe <jdoe@example.com>’

Returns Git::Actor.

# File lib/grit/actor.rb, line 18
def self.from_string(str)
  case str
    when /<.+>/
      m, name, email = *str.match(/(.*) <(.+?)>/)
      return self.new(name, email)
    else
      return self.new(str, nil)
  end
end
new(name, email) click to toggle source
# File lib/grit/actor.rb, line 7
def initialize(name, email)
  @name = name
  @email = email
end

Public Instance Methods

inspect() click to toggle source

Pretty object inspection

# File lib/grit/actor.rb, line 47
def inspect
  %{#<Grit::Actor "#{@name} <#{@email}>">}
end
output(time) click to toggle source

Outputs an actor string for Git commits.

actor = Actor.new('bob', 'bob@email.com')
actor.output(time) # => "bob <bob@email.com> UNIX_TIME +0700"

time - The Time the commit was authored or committed.

Returns a String.

# File lib/grit/actor.rb, line 36
def output(time)
  out = @name.to_s.dup
  if @email
    out << " <#{@email}>"
  end
  hours = (time.utc_offset.to_f / 3600).to_i # 60 * 60, seconds to hours
  rem   = time.utc_offset.abs % 3600
  out << " #{time.to_i} #{hours >= 0 ? :+ : :-}#{hours.abs.to_s.rjust(2, '0')}#{rem.to_s.rjust(2, '0')}"
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.