Class: UnreleasedSection

Inherits:
Object
  • Object
show all
Defined in:
lib/ratatui_ruby/devtools/tasks/bump/unreleased_section.rb

Overview

Manages the Unreleased section of a changelog.

Changelogs accumulate changes under an Unreleased heading. During a release, this section becomes a dated version entry. Parsing and transforming it by hand is tedious.

This class extracts the Unreleased section from markdown. It transforms it into a versioned section. It generates commit message bodies.

Use it during release preparation.

Constant Summary collapse

PATTERN =

Regex to match the Unreleased section.

/^(## \[Unreleased\].*?)(?=## \[\d)/m

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ UnreleasedSection

Creates a new UnreleasedSection.

content

The raw section text.



41
42
43
# File 'lib/ratatui_ruby/devtools/tasks/bump/unreleased_section.rb', line 41

def initialize(content)
  @content = content.dup
end

Class Method Details

.freshObject

Returns a fresh Unreleased section with standard headings.



34
35
36
# File 'lib/ratatui_ruby/devtools/tasks/bump/unreleased_section.rb', line 34

def self.fresh
  new("## [Unreleased]\n\n### Added\n\n### Changed\n\n### Fixed\n\n### Removed")
end

.parse(content) ⇒ Object

Parses the Unreleased section from changelog content.

content

The full changelog text.



28
29
30
31
# File 'lib/ratatui_ruby/devtools/tasks/bump/unreleased_section.rb', line 28

def self.parse(content)
  match = content.match(PATTERN)
  new(match[1].strip) if match
end

Instance Method Details

#as_version(new_version) ⇒ Object

Converts the section to a dated version entry.

new_version

The version string or SemVer.



48
49
50
51
# File 'lib/ratatui_ruby/devtools/tasks/bump/unreleased_section.rb', line 48

def as_version(new_version)
  date = Date.today.iso8601
  @content.sub(/^## \[Unreleased\]/, "## [#{new_version}] - #{date}")
end

#commit_bodyObject

Generates a commit message body from the changes.

Strips markdown formatting and wraps lines to 72 characters.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ratatui_ruby/devtools/tasks/bump/unreleased_section.rb', line 61

def commit_body
  formatter = Class.new { include RDoc::Text }.new
  @content
    .sub(/^## \[Unreleased\].*$/, "")
    .gsub(/^### (Added|Changed|Fixed|Removed)\n*$/, "")
    .gsub(/^- \*\*([^*]+)\*\*:/, '\1:')
    .gsub(/`([^`]+)`/, '\1')
    .strip
    .lines
    .map { |line| line.gsub(/^- /, "").strip }
    .reject(&:empty?)
    .map { |line| formatter.wrap(line, 72) }
    .join("\n\n")
end

#to_sObject

Returns the section as a string.



54
55
56
# File 'lib/ratatui_ruby/devtools/tasks/bump/unreleased_section.rb', line 54

def to_s
  @content
end