class PrChangelog::GroupedChanges

A class to group change lines by tag

Attributes

changes[R]
tags[R]

Public Class Methods

new(changes, tags) click to toggle source
# File lib/pr_changelog/grouped_changes.rb, line 8
def initialize(changes, tags)
  @changes = changes
  @tags = tags
end

Public Instance Methods

to_s() click to toggle source
# File lib/pr_changelog/grouped_changes.rb, line 13
def to_s
  new_hash = {}
  grouped_changes.each do |tag, change_lines|
    new_key = tag.formatted_title
    new_hash[new_key] = change_lines.map do |change_line|
      change_line.emojified_for(tag)
    end
  end

  new_hash.reduce('') do |string, pair|
    tag   = pair[0]
    lines = pair[1].map { |l| "  #{l}" }.join("\n")
    string + "#{tag}\n#{lines}\n\n"
  end.strip.chomp
end

Private Instance Methods

grouped_changes() click to toggle source
# File lib/pr_changelog/grouped_changes.rb, line 31
def grouped_changes
  @grouped_changes ||= changes.group_by do |change_line|
    tags[change_line&.tag&.downcase] || tags['unclassified']
  end.sort do |first_group, second_group|
    first_group[0].sort_index <=> second_group[0].sort_index
  end
end