Class: Reissue::Markdown

Inherits:
Object
  • Object
show all
Defined in:
lib/reissue/markdown.rb

Defined Under Namespace

Classes: Change, Header, Version

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(changelog) ⇒ Markdown

Returns a new instance of Markdown.



7
8
9
10
11
12
# File 'lib/reissue/markdown.rb', line 7

def initialize(changelog)
  @changelog = changelog
  @versions = {}
  @header = nil
  @parts = []
end

Class Method Details

.parse(changelog) ⇒ Object



3
4
5
# File 'lib/reissue/markdown.rb', line 3

def self.parse(changelog)
  new(changelog).to_h
end

Instance Method Details

#parseObject



14
15
16
17
18
19
20
21
# File 'lib/reissue/markdown.rb', line 14

def parse
  return unless @header.nil? && @versions.empty?

  header, *chunks = @changelog.split(/^## /)

  @header = Header.new(header)
  @versions = Array(chunks).map { |part| Version.new(part) }
end

#to_hObject



23
24
25
26
# File 'lib/reissue/markdown.rb', line 23

def to_h
  parse
  @header.to_h.merge("versions" => @versions.map(&:to_h))
end