class GitReporting::Report

Attributes

children[R]
key[R]

Public Class Methods

build(commits) { |commits| ... } click to toggle source
# File lib/git_reporting/report.rb, line 15
def self.build(commits)
  hash = Hash.new { |h, k| h[k] = [] }
  commits.each { |commit| hash[key_for_commit(commit)] << commit }
  hash.map do |key, commits|
    new(key) << (block_given? ? yield(commits) : Commit.new_from_collection(commits))
  end
end
key_for_commit(commit) click to toggle source
# File lib/git_reporting/report.rb, line 23
def self.key_for_commit(commit)
  nil
end
new(key = nil) click to toggle source
# File lib/git_reporting/report.rb, line 27
def initialize(key = nil)
  @key = key
  @children = []
end
new_from_collection(collection) click to toggle source
# File lib/git_reporting/report.rb, line 9
def self.new_from_collection(collection)
  raise ArgumentError, "#{collection.inspect} is not a collection" unless collection.respond_to?(:each)

  collection.map { |item| new(item) }
end

Public Instance Methods

<<(child)
Alias for: append_child
append_child(child) click to toggle source
# File lib/git_reporting/report.rb, line 32
def append_child(child)
  if child.respond_to?(:each)
    child.each { |c| self.append_child(c) }
  else
    raise ArgumentError, "Attempting to add a nil node" unless child
    raise ArgumentError, "Only Report and its descendants can be added as a children" unless child.is_a?(Report)
    raise ArgumentError, "Attempting add node to itself" if self.equal?(child)

    children << child
  end
  self
end
Also aliased as: <<
print() click to toggle source
time() click to toggle source
# File lib/git_reporting/report.rb, line 46
def time
  @time ||= children.inject(0) { |time, child| time + child.time }
end
to_s() click to toggle source
# File lib/git_reporting/report.rb, line 50
def to_s
  "#{self.class.name} : #{key} : #{time}"
end