Sha256: b8e711dfc9ec3bb6bc3728043c850401c52f4b2efd105088cbb2c0be87371fc2

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

require_relative '../hash_initializable'
require_relative '../inspector'

module GitStats
  module GitData
    class Author
      include GitStats::HashInitializable
      include GitStats::Inspector

      attr_reader :repo, :name, :email

      def commits
        @commits ||= repo.commits.select { |commit| commit.author == self }
      end

      def commits_sum
        commits.size
      end

      def changed_lines
        insertions + deletions
      end

      def insertions
        short_stats.sum(&:insertions)
      end

      def deletions
        short_stats.sum(&:deletions)
      end

      def commits_sum_by_date
        sum = 0
        commits.map do |commit|
          sum += 1
          [commit.date, sum]
        end
      end

      [:insertions, :deletions, :changed_lines].each do |method|
        define_method "total_#{method}_by_date" do
          sum = 0
          commits.map do |commit|
            sum += commit.short_stat.send(method)
            [commit.date, sum]
          end
        end

        define_method "#{method}_by_date" do
          commits.group_by { |c| c.date.to_date }.map { |arr| [arr[0], arr[1].sum { |c| c.short_stat.send(method) }] }
        end
      end

      def short_stats
        commits.map(&:short_stat)
      end

      def activity
        @activity ||= Activity.new(commits)
      end

      def dirname
        name.underscore.split.join '_'
      end

      def ==(other)
        [repo, name, email] == [other.repo, other.name, other.email]
      end

      private

      def ivars_to_be_displayed
        [:@name, :@email]
      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/author.rb