Class: GitWakaTime::Timer

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

Overview

Integrates the nested hash from mapper with actions api

Instance Method Summary collapse

Constructor Details

#initialize(commits, actions_with_durations, project) ⇒ Timer

Returns a new instance of Timer.



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

def initialize(commits, actions_with_durations, project)
  @commits = commits
  @actions_with_durations   = actions_with_durations
  @project   = project
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_actions relevant_actions(commit, file)
        file.time_in_seconds = time
        commit.time_in_seconds = time

        file.save
      end
      commit.save
    else
      commit.time_in_seconds = sum_actions(actions_before(@actions_with_durations, commit.date))
    end
  end.compact
  total
  total_commited
  @commits_with_duration
  @commits_with_duration_by_date = @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_actions @actions_with_durations
  Log.new "Total Recorded time #{ChronicDuration.output total_time}", :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