class CommitMesssageParser

Attributes

line_index[R]

Public Class Methods

new() click to toggle source
# File lib/git/story/prepare-commit-msg, line 9
def initialize
  @line_index         = 0
  @story_number_found = false
  @story_number_done  = false
  @message_data       = []
end

Public Instance Methods

data() click to toggle source
# File lib/git/story/prepare-commit-msg, line 47
def data
  @message_data[0..@line_index]
end
parse(template) click to toggle source
# File lib/git/story/prepare-commit-msg, line 26
def parse(template)
  @message_data = template.readlines
  @message_data.each do |line|
    if /^\s*\[.*(?:#\d+|TODO|(?<done>DONE)).*\]/i =~ line
      @story_number_found = true
      if @story_number_done  = !!done
        @message_data.slice!(@line_index)
        next
      end
    end
    if line =~ /^\s*#/
      break
    else
      @line_index += 1
    end
  end
ensure
  @line_index = [ @line_index - 1, 0 ].max
  return self
end
story_number_done?() click to toggle source
# File lib/git/story/prepare-commit-msg, line 22
def story_number_done?
  @story_number_done
end
story_number_found?() click to toggle source
# File lib/git/story/prepare-commit-msg, line 18
def story_number_found?
  @story_number_found
end
total() click to toggle source
# File lib/git/story/prepare-commit-msg, line 55
def total
  data + footer
end