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, time = nil) ⇒ Actor

Returns a new instance of Actor.



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

def initialize(name, email, time = nil)
  @name = name
  @email = email
  @time = time
  @person_ident = @time ? PersonIdent.new(name, email, time.to_java, TimeZone.getTimeZone(time.zone)) : PersonIdent.new(name, email)
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



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

def email
  @email
end

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



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

def name
  @name
end

#person_identObject (readonly)

Returns the value of attribute person_ident.



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

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.



33
34
35
36
37
38
# File 'lib/actor.rb', line 33

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



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

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 = nil) ⇒ 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.



48
49
50
51
52
53
54
55
56
57
# File 'lib/actor.rb', line 48

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

#timeObject



59
60
61
# File 'lib/actor.rb', line 59

def time
  Time.at(@person_ident.getWhen.getTime/1000)
end