class NTYChangeLog::Parser

Public Instance Methods

parse(text) click to toggle source
# File lib/nty_change_log/parser.rb, line 3
def parse(text)
  versions = parse_versions(text.strip)
  ChangeLog.new(versions)
end
parse_change_groups(text) click to toggle source
# File lib/nty_change_log/parser.rb, line 17
def parse_change_groups(text)
  return [] if text.empty?
  result = text.split(/^### (.+)$/)[1..-1].map(&:strip)
  Hash[*result].map do |name, change_texts|
    changes = parse_changes(change_texts)
    ChangeGroup.new(name, changes)
  end
end
parse_changes(text) click to toggle source
# File lib/nty_change_log/parser.rb, line 26
def parse_changes(text)
  return [] if text.empty?
  rows = text.split("\n").map(&:strip)
  rows.map do |row|
    if match = row.match(/\[#(?<number>\d+)\]\((?<url>\S+)\)/)
      issue = Issue.new(match[:number].to_i, match[:url])
      description = row.gsub(/\*\s*(.+)\s+\[#\d+\]\(\S+\)$/) { $1 }
      Change.new(description, issue)
    else
      description = row.gsub(/\*\s*(.+)$/) { $1 }
      Change.new(description, nil)
    end
  end
end
parse_versions(text) click to toggle source
# File lib/nty_change_log/parser.rb, line 8
def parse_versions(text)
  return [] if text.empty?
  result = text.split(/^## (.+)$/)[1..-1].map(&:strip)
  Hash[*result].map do |name, change_group_texts|
    change_groups = parse_change_groups(change_group_texts)
    Version.new(name, change_groups)
  end
end