class Changelog::Entry

Constants

TYPES
Type

Attributes

author[R]
issue[R]
merge_request[R]
title[R]
type[R]

Public Class Methods

from_yml(path) click to toggle source
# File lib/changelog/entry.rb, line 22
def from_yml(path)
        parse_blob(File.read(path))
end
new(title, type, author, issue, merge_request) click to toggle source
# File lib/changelog/entry.rb, line 36
def initialize(title, type, author, issue, merge_request)
        @title = title
        @type = parse_type(type) 
        @author = author 
        @issue = issue
        @merge_request = merge_request
end

Private Class Methods

parse_blob(content) click to toggle source
# File lib/changelog/entry.rb, line 28
def parse_blob(content) 
        yaml = YAML.safe_load(content)

        Entry.new(yaml['title'], yaml['type'], yaml['author'], yaml['issue'], yaml['merge_request'])
end

Public Instance Methods

to_s() click to toggle source
# File lib/changelog/entry.rb, line 44
def to_s
        str = +""
        str << "#{title}".gsub(/\.{2,}$/, '.')
        str << " ##{issue}" if !issue.nil?
        str << " !#{merge_request}" if !merge_request.nil?
        str << " (#{author})" if !author.nil?

        str
end
to_yml() click to toggle source
# File lib/changelog/entry.rb, line 58
def to_yml
        yaml_content = YAML.dump(
                'title'         => @title,
                'type'          => @type,
                'issue'         => @issue,
                'merge_request' => @merge_request,
                'author'        => @author,
        )
        remove_trailing_whitespace(yaml_content)
end
valid?() click to toggle source
# File lib/changelog/entry.rb, line 54
def valid?
        !@title.nil?
end

Private Instance Methods

parse_type(type) click to toggle source
# File lib/changelog/entry.rb, line 71
def parse_type(type)
        TYPES.map(&:name).include?(type) ? type : 'other'
end
remove_trailing_whitespace(yaml_content) click to toggle source
# File lib/changelog/entry.rb, line 75
def remove_trailing_whitespace(yaml_content)
        yaml_content.gsub(/ +$/, '')
end