Class: Danger::Changelog::ChangelogLine

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

Overview

An abstract CHANGELOG.md line.

Constant Summary collapse

NON_DELIMITERS =
/[^(){}\[\]]*/.freeze
PAIRED =
/\(#{NON_DELIMITERS}\)|\{#{NON_DELIMITERS}\}|\[#{NON_DELIMITERS}\]/.freeze
DELIMITER =
/[(){}\[\]]/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ ChangelogLine

Returns a new instance of ChangelogLine.



12
13
14
15
# File 'lib/changelog/changelog_line/changelog_line.rb', line 12

def initialize(line)
  self.line = line
  self.validation_result = nil
end

Instance Attribute Details

#lineObject

Returns the value of attribute line.



9
10
11
# File 'lib/changelog/changelog_line/changelog_line.rb', line 9

def line
  @line
end

#validation_resultObject

Returns the value of attribute validation_result.



10
11
12
# File 'lib/changelog/changelog_line/changelog_line.rb', line 10

def validation_result
  @validation_result
end

Class Method Details

.validates_as_changelog_line?(_line) ⇒ Boolean

Match the given line if it potentially represents the specific changelog line

Returns:

  • (Boolean)


28
29
30
# File 'lib/changelog/changelog_line/changelog_line.rb', line 28

def self.validates_as_changelog_line?(_line)
  abort "You need to include a function for #{self} for validates_as_changelog_line?"
end

Instance Method Details

#balanced?(line_with_parens) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/changelog/changelog_line/changelog_line.rb', line 33

def balanced?(line_with_parens)
  line_with_parens = line_with_parens.dup
  line_with_parens.gsub!(PAIRED, ''.freeze) while line_with_parens =~ PAIRED
  line_with_parens !~ DELIMITER
end

#invalid?Boolean

Match the line with the validation rules opposite to valid?

Returns:

  • (Boolean)


23
24
25
# File 'lib/changelog/changelog_line/changelog_line.rb', line 23

def invalid?
  !valid?
end

#valid?Boolean

Match the line with the validation rules

Returns:

  • (Boolean)


18
19
20
# File 'lib/changelog/changelog_line/changelog_line.rb', line 18

def valid?
  raise 'ChangelogLine subclass must implement the valid? method'
end