Class: Grit::Actor

Inherits:
Object
  • Object
show all
Defined in:
lib/grit/actor.rb,
lib/grit_ext/actor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, email) ⇒ Actor

Returns a new instance of Actor.



7
8
9
10
# File 'lib/grit/actor.rb', line 7

def initialize(name, email)
  @name = name
  @email = email
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



5
6
7
# File 'lib/grit/actor.rb', line 5

def email
  @email
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/grit/actor.rb', line 4

def name
  @name
end

Class Method Details

.from_string(str) ⇒ Object

Create an Actor from a string.

str - The String in this format: ‘John Doe <[email protected]>’

Returns Git::Actor.



18
19
20
21
22
23
24
25
26
# 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

Instance Method Details

#inspectObject

Pretty object inspection



47
48
49
# File 'lib/grit/actor.rb', line 47

def inspect
  %Q{#<Grit::Actor "#{@name} <#{@email}>">}
end

#old_emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/grit_ext/actor.rb', line 5

def email
  @email
end

#old_nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/grit_ext/actor.rb', line 4

def name
  @name
end

#output(time) ⇒ Object

Outputs an actor string for Git commits.

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

time - The Time the commit was authored or committed.

Returns a String.



36
37
38
39
40
41
42
43
44
# File 'lib/grit/actor.rb', line 36

def output(time)
  offset = time.utc_offset / 60
  "%s <%s> %d %+.2d%.2d" % [
    @name,
    @email || "null",
    time.to_i,
    offset / 60,
    offset.abs % 60]
end

#to_sObject

Returns the value of attribute name.



11
12
13
# File 'lib/grit/actor.rb', line 11

def name
  @name
end