Class: Git::Changelog::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/git-changes/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ Parser

Returns a new instance of Parser.



2
3
4
# File 'lib/git-changes/parser.rb', line 2

def initialize(io)
  @io = io
end

Instance Method Details

#generate_changelogObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/git-changes/parser.rb', line 6

def generate_changelog
  commit = nil
  @io.each_line do |line|

    case line
    when /^commit ([0123456789abcdef]{6,40})$/
      process_commit(commit) if commit
      commit = {:id => $1}
    when /^Author: (.*)/
      commit[:author] = $1
    when /^Date:\s+(.*)$/
      commit[:date] = $1
    when / (delete mode|create mode) \d{3,6} ([\S]+)\s*$/, /^( )([^\s]*)\s+\|\s+\d+ [-+]*\s*$/,/^ mode change \d+ => (\d+) ([\S]*)\s*$/ 
      commit[:files] ||= []
      file = File.basename($3 || $3 || $3 || $2)
      commit[:files] << file unless commit[:files].include?(file)
    when /.*files changed.*insertions.*deletions/
    when /^    (.*)$/
      commit[:message] ||= ""
      commit[:message] << $1 << "\n"
    end
  end
  process_commit(commit) if commit
end