Class: Ballantine::Author

Inherits:
Object
  • Object
show all
Includes:
Printable
Defined in:
lib/ballantine/author.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Printable

#cols, #puts_r, #rjust_size

Constructor Details

#initialize(name:) ⇒ Author

Returns a new instance of Author.

Parameters:



32
33
34
35
# File 'lib/ballantine/author.rb', line 32

def initialize(name:)
  @name = name
  @commits_hash = {}
end

Instance Attribute Details

#commits_hashObject (readonly)

Returns the value of attribute commits_hash.



7
8
9
# File 'lib/ballantine/author.rb', line 7

def commits_hash
  @commits_hash
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/ballantine/author.rb', line 7

def name
  @name
end

Class Method Details

.allArray<Author>

Returns authors.

Returns:



24
25
26
27
28
# File 'lib/ballantine/author.rb', line 24

def all
  return [] unless defined?(@_collections)

  @_collections.sort.map(&:last) # sort and take values
end

.find(name:) ⇒ Author, NilClass

Parameters:

Returns:



12
13
14
15
# File 'lib/ballantine/author.rb', line 12

def find(name:)
  @_collections = {} unless defined?(@_collections)
  @_collections[name]
end

.find_or_create_by(name:) ⇒ Author

Parameters:

Returns:



19
20
21
# File 'lib/ballantine/author.rb', line 19

def find_or_create_by(name:)
  find(name:) || @_collections[name] = new(name:)
end

Instance Method Details

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ballantine/author.rb', line 38

def print_commits
  conf.print_log(binding) if conf.verbose

  puts "\n" + "@#{name}".green
  commits_hash.each do |repo_name, commits|
    count, word = retrieve_count_and_word(commits)
    puts " > #{repo_name.blue}: #{count} new #{word}"
    commits.each do |commit|
      puts_r " - #{commit.hash.yellow} #{commit.subject}", commit.url.gray
    end
  end

  true
end

#slack_messageHash

returns an array to use slack attachments field reference: api.slack.com/messaging/composing/layouts#building-attachments

Returns:

  • (Hash)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ballantine/author.rb', line 56

def slack_message
  conf.print_log(binding) if conf.verbose

  message = commits_hash.map do |repo_name, commits|
    count, word = retrieve_count_and_word(commits)
    "*#{repo_name}*: #{count} new #{word}\n" \
      "#{commits.map(&:slack_message).join("\n")}"
  end.join("\n")

  {
    "text" => "- <@#{name}>\n#{message}",
    "color" => "#00B86A", # green
  }
end