Class: PrChangelog::GroupedChanges

Inherits:
Object
  • Object
show all
Defined in:
lib/pr_changelog/grouped_changes.rb

Overview

A class to group change lines by tag

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(changes, tags) ⇒ GroupedChanges

Returns a new instance of GroupedChanges.



8
9
10
11
# File 'lib/pr_changelog/grouped_changes.rb', line 8

def initialize(changes, tags)
  @changes = changes
  @tags = tags
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



6
7
8
# File 'lib/pr_changelog/grouped_changes.rb', line 6

def changes
  @changes
end

#tagsObject (readonly)

Returns the value of attribute tags.



6
7
8
# File 'lib/pr_changelog/grouped_changes.rb', line 6

def tags
  @tags
end

Instance Method Details

#to_sObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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