Sha256: b82db2bf21f6fbab502f2765bb5109960f449e5b993e8df3f5888f439bd023e2

Contents?: true

Size: 993 Bytes

Versions: 3

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

module GitStats
  class CommandParser
    def parse(command, result)
      cmd, params = command.scan(/git (.*) (.*)/).first.map(&:split).flatten
      # TODO: params is not needed?
      send("parse_#{cmd.underscore}", result, params)
    end

    def parse_shortlog(result, _params)
      result.lines.map do |line|
        commits, name, email = line.scan(/(.*)\t(.*)<(.*)>/).first.map(&:strip)
        {commits: commits.to_i, name: name, email: email}
      end
    end

    def parse_ls_tree(result, _params)
      result.lines.map do |line|
        mode, type, sha, filename = line.scan(/(.*) (.*) (.*)\t(.*)/).first.map(&:strip)
        {mode: mode, type: type, sha: sha, filename: filename}
      end
    end

    def parse_rev_list(result, _params)
      result.lines.map do |line|
        sha, stamp, date, author_email = line.split('|').map(&:strip)
        {sha: sha, stamp: stamp, date: date, author_email: author_email}
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nova_git_stats-2.4.1 lib/git_stats/command_parser.rb
nova_git_stats-2.4.0 lib/git_stats/command_parser.rb
nova_git_stats-2.3.0 lib/git_stats/command_parser.rb