class JenkinsPivotal::ChangelogParser

Attributes

data[R]
entries[R]

Public Class Methods

new(path) click to toggle source
# File lib/jenkins_pivotal/changelog_parser.rb, line 5
def initialize(path)
  @data = ''
  @entries = []

  if File.exists? path
    @data = File.read path
    load_entries
  end
end

Private Instance Methods

load_entries() click to toggle source
# File lib/jenkins_pivotal/changelog_parser.rb, line 17
def load_entries
  blocks = @data.split /^(commit [a-f0-9]{40})/

  if blocks.empty?
    return
  end

  # If the first line is `commit ...`, the first item of the array will
  # be an empty string.
  if '' == blocks[0]
    blocks.shift
  end

  # The first line may be something else entirely, like:
  # Changes in branch origin/master, between ...
  if !blocks[0].start_with? 'commit'
    blocks.shift
  end

  blocks.each_slice(2) do |block|
    @entries.push ChangelogEntry.new(block[0] + block[1])
  end
end