Class: Ballantine::Author

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Author

Returns a new instance of Author.

Parameters:



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

def initialize(name)
  @name = name
  @commits = {}
end

Instance Attribute Details

#commitsObject

Returns the value of attribute commits.



5
6
7
# File 'lib/ballantine/author.rb', line 5

def commits
  @commits
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/ballantine/author.rb', line 5

def name
  @name
end

Class Method Details

.allArray<Author>

Returns authors.

Returns:



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

def all
  return [] unless defined?(@@_collections)
  @@_collections.sort.map(&:last) # sort and take values
end

.find_or_create_by(name) ⇒ Author

Returns author.

Parameters:

Returns:



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

def find_or_create_by(name)
  @@_collections = {} unless defined?(@@_collections)
  return @@_collections[name] unless @@_collections[name].nil?
  @@_collections[name] = new(name)
end

Instance Method Details

Returns nil.

Returns:

  • (NilClass)

    nil



30
31
32
33
34
35
36
37
38
# File 'lib/ballantine/author.rb', line 30

def print_commits
  puts "\n" + "@#{name}".green
  @commits.each do |repo, lists|
    count, word = retrieve_count_and_word(lists)
    puts " > #{repo.blue}: #{count} new #{word}\n"
    puts lists
  end
  nil
end

#serialize_commitsHash

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

Returns:

  • (Hash)

    result



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ballantine/author.rb', line 43

def serialize_commits
  message = @commits.map do |repo, lists|
    count, word = retrieve_count_and_word(lists)
    "*#{repo}*: #{count} new #{word}\n#{lists.join("\n")}"
  end.join("\n")

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