Class: GitHubChangelogGenerator::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/github_changelog_generator/generator/section.rb

Overview

This class generates the content for a single section of a changelog entry. It turns the tagged issues and PRs into a well-formatted list of changes to be later incorporated into a changelog entry.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Section

Returns a new instance of Section.



28
29
30
31
32
33
34
35
36
# File 'lib/github_changelog_generator/generator/section.rb', line 28

def initialize(opts = {})
  @name = opts[:name]
  @prefix = opts[:prefix]
  @labels = opts[:labels] || []
  @issues = opts[:issues] || []
  @options = opts[:options] || Options.new({})
  @body_only = opts[:body_only] || false
  @entry = Entry.new(options)
end

Instance Attribute Details

#body_onlyBoolean (readonly)

Returns:

  • (Boolean)


23
24
25
# File 'lib/github_changelog_generator/generator/section.rb', line 23

def body_only
  @body_only
end

#issuesArray<Hash> (readonly)

Returns:

  • (Array<Hash>)


17
18
19
# File 'lib/github_changelog_generator/generator/section.rb', line 17

def issues
  @issues
end

#labelsArray<String> (readonly)

Returns:

  • (Array<String>)


20
21
22
# File 'lib/github_changelog_generator/generator/section.rb', line 20

def labels
  @labels
end

#nameString

Returns:

  • (String)


11
12
13
# File 'lib/github_changelog_generator/generator/section.rb', line 11

def name
  @name
end

#optionsOptions (readonly)

Returns:



26
27
28
# File 'lib/github_changelog_generator/generator/section.rb', line 26

def options
  @options
end

#prefixString (readonly)

Returns a merge prefix, or an issue prefix.

Returns:

  • (String)

    a merge prefix, or an issue prefix



14
15
16
# File 'lib/github_changelog_generator/generator/section.rb', line 14

def prefix
  @prefix
end

Instance Method Details

#generate_contentString

Returns the content of a section.

Returns:

  • (String)

    Generated section content



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/github_changelog_generator/generator/section.rb', line 41

def generate_content
  content = ""

  if @issues.any?
    content += "#{@prefix}\n\n" unless @options[:simple_list] || @prefix.blank?
    @issues.each do |issue|
      merge_string = get_string_for_issue(issue)
      content += "- " unless @body_only
      content += "#{merge_string}\n"
    end
    content += "\n"
  end
  content
end