Class: CommitStatisticsForCommitterInRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/codespicuous/commitstatistics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommitStatisticsForCommitterInRepository

Returns a new instance of CommitStatisticsForCommitterInRepository.



7
8
9
# File 'lib/codespicuous/commitstatistics.rb', line 7

def initialize
  self.commits = {}
end

Instance Attribute Details

#commits=(value) ⇒ Object (writeonly)

Sets the attribute commits

Parameters:

  • value

    the value to set the attribute commits to.



5
6
7
# File 'lib/codespicuous/commitstatistics.rb', line 5

def commits=(value)
  @commits = value
end

Instance Method Details

#amount_of_commitsObject



16
17
18
# File 'lib/codespicuous/commitstatistics.rb', line 16

def amount_of_commits
  @commits.values.inject(0) { |sum, commits_of_week| sum += commits_of_week }
end

#amount_of_commits_in_week(week_start) ⇒ Object



24
25
26
# File 'lib/codespicuous/commitstatistics.rb', line 24

def amount_of_commits_in_week week_start
  @commits[week_start] ? @commits[week_start] : 0
end

#amount_of_weeks_committedObject



20
21
22
# File 'lib/codespicuous/commitstatistics.rb', line 20

def amount_of_weeks_committed
  @commits.size
end

#commit(date, amount) ⇒ Object



11
12
13
14
# File 'lib/codespicuous/commitstatistics.rb', line 11

def commit(date, amount)
  @commits[DateTime.parse(date.to_s)] ||= 0
  @commits[DateTime.parse(date.to_s)] += amount.to_i
end

#first_week_committedObject



28
29
30
31
32
33
34
# File 'lib/codespicuous/commitstatistics.rb', line 28

def first_week_committed
  commit_week = DateTime.now
  @commits.each_key { |date|
    commit_week = date if date < commit_week
  }
  commit_week
end

#last_week_committedObject



36
37
38
39
40
41
42
# File 'lib/codespicuous/commitstatistics.rb', line 36

def last_week_committed
  commit_week = DateTime.new(1977)
  @commits.each_key { |date|
    commit_week = date if date > commit_week
  }
  commit_week
end