Sha256: d88df45793657bf8801388461d10fc8dbff1dadb23bb5bf5448466f9c307e831

Contents?: true

Size: 1.13 KB

Versions: 29

Compression:

Stored size: 1.13 KB

Contents

module Grit

  class Actor
    attr_reader :name
    attr_reader :email

    def initialize(name, email)
      @name = name
      @email = email
    end
    alias_method :to_s, :name

    # 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)
      case str
        when /<.+>/
          m, name, email = *str.match(/(.*) <(.+?)>/)
          return self.new(name, email)
        else
          return self.new(str, nil)
      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

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

end # Grit

Version data entries

29 entries across 29 versions & 4 rubygems

Version Path
gitlab-grit-2.8.3 lib/grit/actor.rb
gitlab-grit-2.8.2 lib/grit/actor.rb
gitlab-grit-2.8.1 lib/grit/actor.rb
gitlab-grit-2.8.0 lib/grit/actor.rb
gitlab-grit-2.7.3 lib/grit/actor.rb
gitlab-grit-2.6.12 lib/grit/actor.rb
gitlab-grit-2.7.2 lib/grit/actor.rb
gitlab-grit-2.6.11 lib/grit/actor.rb
gitlab-grit-2.7.1 lib/grit/actor.rb
gitlab-grit-2.6.10 lib/grit/actor.rb
gitlab-grit-2.7.0 lib/grit/actor.rb
gitlab-grit-2.6.9 lib/grit/actor.rb
gitlab-grit-2.6.8 lib/grit/actor.rb
gitlab-grit-2.6.7 lib/grit/actor.rb
gitlab-grit-2.6.6 lib/grit/actor.rb
gitlab-grit-2.6.5 lib/grit/actor.rb
gitlab-grit-2.6.4 lib/grit/actor.rb
gitlab-grit-2.6.3 lib/grit/actor.rb
gitlab-grit-2.6.2 lib/grit/actor.rb
gitlab-grit-2.5.2 lib/grit/actor.rb