Class: ChangelogFilter

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

Overview

Filters a text or array for changelog entries.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#changelogObject

An array of changelog entries.



47
48
49
# File 'lib/changelog_filter.rb', line 47

def changelog
  @changelog
end

#other_textObject

An array of text lines that are not changelog entries.



50
51
52
# File 'lib/changelog_filter.rb', line 50

def other_text
  @other_text
end

Class Method Details

.FromArray(ary) ⇒ Object

Factory method that creates an instance given an array of strings



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/changelog_filter.rb', line 28

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

.FromString(string) ⇒ Object

Factory method that creates an instance given a text string



20
21
22
23
24
25
# File 'lib/changelog_filter.rb', line 20

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

.patternObject

Returns the grep string that matches changelog entries.



42
43
44
# File 'lib/changelog_filter.rb', line 42

def self.pattern
  '\s*[*-]\s+[^:]+:\s'
end