Sha256: d633c54db77b1ee7eb251d5a9c0990ca219869dfe5f9bebb8d90d35b783c696b

Contents?: true

Size: 1.31 KB

Versions: 44

Compression:

Stored size: 1.31 KB

Contents

module RJGit

  # PersonIdent in JGit
  import 'org.eclipse.jgit.lib.PersonIdent'
  
  class Actor

    attr_reader :name, :email, :person_ident
    
    RJGit.delegate_to(PersonIdent, :@person_ident)
    
    alias_method :to_s, :name
      
    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
    
    def initialize(name, email)
      @name = name
      @email = email
      @person_ident = PersonIdent.new(name, email)
    end
    
    # Create an Actor from a string.
    #
    # str - The String in this format: 'John Doe <jdoe@example.com>'
    #
    # Returns Git::Actor.
    def self.from_string(str)
      if str =~ /<.+>/
        m, name, email = *str.match(/(.*) <(.+?)>/)
        return self.new(name, email)
      end
    end

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

  end 

end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
rjgit-4.6.1.0 lib/actor.rb
rjgit-4.5.0.0 lib/actor.rb
rjgit-4.4.1.0 lib/actor.rb
rjgit-4.4.0.0 lib/actor.rb
rjgit-4.3.1.0 lib/actor.rb
rjgit-4.2.0.1 lib/actor.rb
rjgit-4.2.0.0 lib/actor.rb
rjgit-4.1.1.0 lib/actor.rb
rjgit-4.1.0.0 lib/actor.rb
rjgit-4.0.3.0 lib/actor.rb
rjgit-4.0.1.0 lib/actor.rb
rjgit-0.3.12 lib/actor.rb
rjgit-0.3.11 lib/actor.rb
rjgit-0.3.10 lib/actor.rb
rjgit-0.3.9 lib/actor.rb
rjgit-0.3.8 lib/actor.rb
rjgit-0.3.7 lib/actor.rb
rjgit-0.3.6 lib/actor.rb
rjgit-0.3.5 lib/actor.rb
rjgit-0.3.4 lib/actor.rb