Sha256: a8a40fa93c518e74ae5487c81ebbd964bf2b9b731c4dc2672cc3bb0b9900af21
Contents?: true
Size: 1.55 KB
Versions: 4
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true module GitStats module GitData class Activity def initialize(commits) add_commits(commits) end def by_date @by_date ||= default_hash end def by_hour @by_hour ||= default_hash end def by_hour_array by_hour.to_key_indexed_array(min_size: 24, default: 0) end def by_wday @by_wday ||= default_hash end def by_wday_array by_wday.to_key_indexed_array(min_size: 7, default: 0) end def by_wday_hour @by_wday_hour ||= default_double_hash end def by_month @by_month ||= default_hash end def by_month_array by_month.to_key_indexed_array(min_size: 13, default: 0)[1..-1] end def by_year @by_year ||= default_hash end def by_year_month @by_year_month ||= default_double_hash end private def add_commits(commits) commits = commits.values if commits.is_a? Hash commits.each do |commit| add_commit_at(commit.date) end end def add_commit_at(date) by_date[date] += 1 by_hour[date.hour] += 1 by_wday[date.wday] += 1 by_wday_hour[date.wday][date.hour] += 1 by_month[date.month] += 1 by_year[date.year] += 1 by_year_month[date.year][date.month] += 1 end def default_hash Hash.new(0) end def default_double_hash Hash.new { |h, k| h[k] = Hash.new(0) } end end end end
Version data entries
4 entries across 4 versions & 1 rubygems