Sha256: c264cd217b78d47cd8f4c5878bdfbae7fdff6aaa306a0a2e92b5c66e538c1286

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

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

1 entries across 1 versions & 1 rubygems

Version Path
nova_git_stats-2.2.0 lib/git_stats/git_data/activity.rb