Class: GitWakaTime::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitwakatime/timer.rb

Overview

Integrates the nested hash from mapper with heartbeats api

Instance Method Summary collapse

Constructor Details

#initialize(commits, heartbeats_with_durations) ⇒ Timer

Returns a new instance of Timer.



9
10
11
12
# File 'lib/gitwakatime/timer.rb', line 9

def initialize(commits, heartbeats_with_durations)
  @commits = commits
  @heartbeats_with_durations = heartbeats_with_durations
end

Instance Method Details

#processObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gitwakatime/timer.rb', line 26

def process
  @commits_with_duration = @commits.each do |commit|
    if commit.commited_files.count > 0 || commit.parent_sha
      commit.commited_files.each_with_index do |file, _i|
        time = sum_heartbeats relevant_heartbeats(commit, file)
        file.time_in_seconds = time
        commit.time_in_seconds = time

        file.save
      end
      commit.save
    else
      commit.time_in_seconds = sum_heartbeats(
        heartbeats_before(@heartbeats_with_durations, commit.date)
      )
    end
  end.compact
  total
  total_commited
  @commits_with_duration.group_by { |c| c.date.to_date }
end

#totalObject



14
15
16
17
# File 'lib/gitwakatime/timer.rb', line 14

def total
  total_time = sum_heartbeats @heartbeats_with_durations
  Log.new "Total Recorded time #{ChronicDuration.output total_time.to_f}", :red
end

#total_commitedObject



19
20
21
22
23
24
# File 'lib/gitwakatime/timer.rb', line 19

def total_commited
  total_commited = ChronicDuration.output(@commits_with_duration
                                          .map(&:time_in_seconds).compact
                                          .reduce(:+).to_f)
  Log.new "Total Committed Time #{total_commited} ".red
end