Class: CommitTime

Inherits:
Object
  • Object
show all
Defined in:
lib/commit-time.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(datetimes) ⇒ CommitTime

Returns a new instance of CommitTime.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/commit-time.rb', line 11

def initialize(datetimes)
  @datetimes = datetimes
  @times = datetimes.each_cons(2).map { |a, b| ((a - b).abs * 24 * 60).round.to_i }
  @commits = datetimes.count

  real_times = @times.find_all { |time| time < 60 }
  @average_time =
    if real_times.empty?
      0
    else
      real_times.reduce(:+).to_f / real_times.count
    end
  @total_time = @average_time * @commits
end

Instance Attribute Details

#average_timeObject (readonly)

Returns the value of attribute average_time.



8
9
10
# File 'lib/commit-time.rb', line 8

def average_time
  @average_time
end

#commitsObject (readonly)

Returns the value of attribute commits.



7
8
9
# File 'lib/commit-time.rb', line 7

def commits
  @commits
end

#datetimesObject (readonly)

Returns the value of attribute datetimes.



4
5
6
# File 'lib/commit-time.rb', line 4

def datetimes
  @datetimes
end

#timesObject (readonly)

Array of times for between each commit, in minutes



6
7
8
# File 'lib/commit-time.rb', line 6

def times
  @times
end

#total_timeObject (readonly)

Returns the value of attribute total_time.



9
10
11
# File 'lib/commit-time.rb', line 9

def total_time
  @total_time
end

Instance Method Details

#marshal_dumpObject



26
27
28
# File 'lib/commit-time.rb', line 26

def marshal_dump
  [@datetimes, @times, @commits, @average_time, @total_time]
end

#marshal_load(array) ⇒ Object



30
31
32
# File 'lib/commit-time.rb', line 30

def marshal_load array
  @datetimes, @times, @commits, @average_time, @total_time = array
end