Class: Git::Duo::Pair

Inherits:
Object
  • Object
show all
Defined in:
lib/git/duo/pair.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authors, opts = {}) ⇒ Pair

Returns a new instance of Pair.



9
10
11
12
# File 'lib/git/duo/pair.rb', line 9

def initialize authors, opts = {}
  @authors = authors.sort_by {|author| author.key }
  @wrapper = opts.fetch(:wrapper) { Git::Duo::Wrapper.new File.join(Dir.pwd, '.git') }
end

Instance Attribute Details

#authorsObject (readonly)

Returns the value of attribute authors.



7
8
9
# File 'lib/git/duo/pair.rb', line 7

def authors
  @authors
end

#wrapperObject (readonly)

Returns the value of attribute wrapper.



7
8
9
# File 'lib/git/duo/pair.rb', line 7

def wrapper
  @wrapper
end

Instance Method Details

#emailObject



18
19
20
21
22
23
24
# File 'lib/git/duo/pair.rb', line 18

def email
  if authors.size > 1
    base_email.gsub "%names", authors.map(&:key).join(?+)
  else
    authors.first.email
  end
end

#nameObject



14
15
16
# File 'lib/git/duo/pair.rb', line 14

def name
  authors.map(&:name).join ' + '
end

#saveObject



31
32
33
34
# File 'lib/git/duo/pair.rb', line 31

def save
  save_pair_name
  save_pair_email
end

#to_sObject Also known as: inspect



26
27
28
# File 'lib/git/duo/pair.rb', line 26

def to_s
  "#{name} <#{email}>"
end