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



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

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

#parse_ls_tree(result, _params) ⇒ Object



18
19
20
21
22
23
# File 'lib/git_stats/command_parser.rb', line 18

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



25
26
27
28
29
30
# File 'lib/git_stats/command_parser.rb', line 25

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



11
12
13
14
15
16
# File 'lib/git_stats/command_parser.rb', line 11

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