Module: JekyllRecker::Date

Included in:
Generators::Base
Defined in:
lib/jekyll_recker/date.rb

Overview

Date Module

Instance Method Summary collapse

Instance Method Details

#calculate_streaks(dates) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/jekyll_recker/date.rb', line 10

def calculate_streaks(dates)
  slice_by_consecutive(dates).map do |pair|
    first, last = pair.minmax
    {
      'days' => (last - first).to_i,
      'start' => first,
      'end' => last
    }
  end
end

#slice_by_consecutive(dates) ⇒ Object



6
7
8
# File 'lib/jekyll_recker/date.rb', line 6

def slice_by_consecutive(dates)
  dates.slice_when { |p, c| c != p - 1 && c != p + 1 }.to_a
end