Class: Metior::ActorCollection

Inherits:
Collection show all
Defined in:
lib/metior/collections/actor_collection.rb

Overview

This class implements a collection of actors and provides functionality specific to actors.

See Also:

Author:

  • Sebastian Staudt

Instance Method Summary collapse

Methods inherited from Collection

#<<, #each, #initialize, #last, #merge!

Constructor Details

This class inherits a constructor from Metior::Collection

Instance Method Details

#authored_commits(actor_id = nil) ⇒ CommitCollection Also known as: commits

Returns the commits authored by all or a specific actor in this collection

Parameters:

  • actor_id (Object) (defaults to: nil)

    The ID of the actor, if only the commits of a specific actor should be returned

Returns:

  • (CommitCollection)

    All commits authored by the actors in this collection or by a specific actor



25
26
27
# File 'lib/metior/collections/actor_collection.rb', line 25

def authored_commits(actor_id = nil)
  load_commits :authored_commits, actor_id
end

#committed_commits(actor_id = nil) ⇒ CommitCollection

Returns the commits committed by all or a specific actor in this collection

Parameters:

  • actor_id (Object) (defaults to: nil)

    The ID of the actor, if only the commits of a specific actor should be returned

Returns:

  • (CommitCollection)

    All commits committed by the actors in this collection or by a specific actor



37
38
39
# File 'lib/metior/collections/actor_collection.rb', line 37

def committed_commits(actor_id = nil)
  load_commits :committed_commits, actor_id
end

#load_commits(commit_type, actor_id = nil) ⇒ CommitCollection (private)

Loads the commits authored or committed by all actors in this collection or a specific actor

Parameters:

  • commit_type (:authored_commits, :committed_commits)

    The type of commits to load

  • actor_id (Object) (defaults to: nil)

    The ID of the actor, if only the commits of a specific actor should be returned

Returns:

  • (CommitCollection)

    All commits authored or committed by the actors in this collection or by a specific actor



85
86
87
88
89
90
91
92
93
# File 'lib/metior/collections/actor_collection.rb', line 85

def load_commits(commit_type, actor_id = nil)
  commits = CommitCollection.new
  if actor_id.nil?
    each { |actor| commits.merge! actor.send(commit_type) }
  elsif key? actor_id
    commits = self[actor_id].send commit_type
  end
  commits
end

#most_significant(count = 3) ⇒ ActorCollection

Returns up to the given number of actors in this collection with the biggest impact on the repository, i.e. changing the most code

Parameters:

  • count (Numeric) (defaults to: 3)

    The number of actors to return

Returns:

See Also:



47
48
49
50
51
52
53
54
55
56
# File 'lib/metior/collections/actor_collection.rb', line 47

def most_significant(count = 3)
  first.support! :line_stats

  authors = ActorCollection.new
  sort_by { |author| -author.modifications }.each do |author|
    authors << author
    break if authors.size == count
  end
  authors
end

#top(count = 3) ⇒ ActorCollection

Returns up to the given number of actors in this collection with the most commits

Parameters:

  • count (Numeric) (defaults to: 3)

    The number of actors to return

Returns:

See Also:



65
66
67
68
69
70
71
72
# File 'lib/metior/collections/actor_collection.rb', line 65

def top(count = 3)
  authors = ActorCollection.new
  sort_by { |author| -author.authored_commits.size }.each do |author|
    authors << author
    break if authors.size == count
  end
  authors
end