Class: RJGit::Actor

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


20
21
22
23
24
# File 'lib/actor.rb', line 20

def initialize(name, email)
  @name = name
  @email = email
  @person_ident = PersonIdent.new(name, email)
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email


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

def email
  @email
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name


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

def name
  @name
end

#person_identObject (readonly)

Returns the value of attribute person_ident


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

def person_ident
  @person_ident
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.


31
32
33
34
35
36
# File 'lib/actor.rb', line 31

def self.from_string(str)
  if str =~ /<.+>/
    m, name, email = *str.match(/(.*) <(.+?)>/)
    return self.new(name, email)
  end
end

.new_from_person_ident(person_ident) ⇒ Object


14
15
16
17
18
# File 'lib/actor.rb', line 14

def self.new_from_person_ident(person_ident)
  name = person_ident.get_name
  email = person_ident.get_email_address
  return self.new(name, email)
end

Instance Method Details

#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.


46
47
48
49
50
51
52
53
54
# File 'lib/actor.rb', line 46

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