Class: Spoom::Timeline

Inherits:
Object
  • Object
show all
Defined in:
lib/spoom/timeline.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, from, to) ⇒ Timeline

: (Context context, Time from, Time to) -> void



7
8
9
10
11
# File 'lib/spoom/timeline.rb', line 7

def initialize(context, from, to)
  @context = context
  @from = from
  @to = to
end

Instance Method Details

#commits_for_dates(dates) ⇒ Object

Return one commit for each date in ‘dates` : (Array dates) -> Array



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/spoom/timeline.rb', line 34

def commits_for_dates(dates)
  dates.map do |t|
    result = @context.git_log(
      "--since='#{t}'",
      "--until='#{t.to_date.next_month}'",
      "--format='format:%h %at'",
      "--author-date-order",
      "-1",
    )
    next if result.out.empty?

    Spoom::Git::Commit.parse_line(result.out.strip)
  end.compact.uniq(&:sha)
end

#monthsObject

Return all months between ‘from` and `to` : -> Array



21
22
23
24
25
26
27
28
29
30
# File 'lib/spoom/timeline.rb', line 21

def months
  d = Date.new(@from.year, @from.month, 1)
  to = Date.new(@to.year, @to.month, 1)
  res = [d.to_time]
  while d < to
    d = d.next_month
    res << d.to_time
  end
  res
end

#ticksObject

Return one commit for each month between ‘from` and `to` : -> Array



15
16
17
# File 'lib/spoom/timeline.rb', line 15

def ticks
  commits_for_dates(months)
end