Class: GitStats::CommandParser

Inherits:
Object
  • Object
show all
Defined in:
lib/git_stats/command_parser.rb

Instance Method Summary collapse

Instance Method Details

#parse(command, result) ⇒ Object


4
5
6
7
# File 'lib/git_stats/command_parser.rb', line 4

def parse(command, result)
  cmd, params = command.scan(/git (.*) (.*)/).first.map(&:split).flatten
  send("parse_#{cmd.underscore}", result, params)
end

#parse_ls_tree(result, params) ⇒ Object


16
17
18
19
20
21
# File 'lib/git_stats/command_parser.rb', line 16

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

#parse_rev_list(result, params) ⇒ Object


23
24
25
26
27
28
# File 'lib/git_stats/command_parser.rb', line 23

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

#parse_shortlog(result, params) ⇒ Object


9
10
11
12
13
14
# File 'lib/git_stats/command_parser.rb', line 9

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