Sha256: f2ed379f28f9bca88b4d10575873c7d9bf48718179ca2f58ac3273be851df991

Contents?: true

Size: 1.65 KB

Versions: 8

Compression:

Stored size: 1.65 KB

Contents

# changelog_filter.rb, part of Create-changelog
# Copyright 2015 Daniel Kraus
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative 'array'

# Filters a text or array for changelog entries.
class ChangelogFilter
	# Factory method that creates an instance given a text string
	def self.FromString(string)
		unless string.is_a?(String)
			fail "Must call this factory with String, not " + string.class.to_s
		end
		self.FromArray(string.chomp.split("\n"))
	end

	# Factory method that creates an instance given an array of strings
	def self.FromArray(ary)
		unless ary.is_a?(Array)
			fail "Must call this factory with Array, not " + ary.class.to_s
		end
		filter = ChangelogFilter.new
		log, text = ary.partition do |line|
			line.match(pattern)
		end
		filter.changelog = log.uniq.sort.remove_indent if log.length > 0
		filter.other_text = text if text.length > 0
		filter
	end

	# Returns the grep string that matches changelog entries.
	def self.pattern
		'\s*[*-]\s+[^:]+:\s'
	end

	# An array of changelog entries.
	attr_accessor :changelog

	# An array of text lines that are not changelog entries.
	attr_accessor :other_text

	private

	def initialize
	end
end

# vim: nospell

Version data entries

8 entries across 6 versions & 1 rubygems

Version Path
create_changelog-1.4.3 lib/changelog_filter.rb
create_changelog-1.4.2 lib/changelog_filter.rb
create_changelog-1.4.1 lib/changelog_filter.rb
create_changelog-1.3.2 lib/changelog_filter.rb~
create_changelog-1.3.2 lib/changelog_filter.rb
create_changelog-1.3.1 lib/changelog_filter.rb~
create_changelog-1.3.1 lib/changelog_filter.rb
create_changelog-1.3.0 lib/changelog_filter.rb