Sha256: 92f4dc3bd8c98299843eaf2887fad941aafd0cc5b6ddc2734f20d63bde5af301

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 Bytes

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

    # Returns this actor in the git format, as taken by from_string
    def to_git_format
      @email ? "#{@name} <#{@email}>" : @name
    end
    
    # Create an Actor from a string.
    #   +str+ is the string, which is expected to be in regular git format
    #
    # Format
    #   John Doe <jdoe@example.com>
    #
    # Returns 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
    
    # Pretty object inspection
    def inspect
      %Q{#<Grit::Actor "#{@name} <#{@email}>">}
    end
  end # Actor
  
end # Grit

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
davetron5000-grit-1.1.2 lib/grit/actor.rb
davetron5000-grit-1.1.3 lib/grit/actor.rb