Sha256: 0be2e5155669362ea7bd16fe6aa48c0b857f8fd5c35fd1bfaa06da4a7a26553e

Contents?: true

Size: 1.23 KB

Versions: 2

Compression:

Stored size: 1.23 KB

Contents

module Danger
  module Changelog
    # An abstract CHANGELOG.md line.
    class ChangelogLine
      NON_DELIMITERS = /[^(){}\[\]]*/.freeze
      PAIRED = /\(#{NON_DELIMITERS}\)|\{#{NON_DELIMITERS}\}|\[#{NON_DELIMITERS}\]/.freeze
      DELIMITER = /[(){}\[\]]/.freeze

      attr_accessor :line
      attr_accessor :validation_result

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

      # Match the line with the validation rules
      def valid?
        raise 'ChangelogLine subclass must implement the valid? method'
      end

      # Match the line with the validation rules opposite to valid?
      def invalid?
        !valid?
      end

      # Match the given line if it potentially represents the specific changelog line
      def self.validates_as_changelog_line?(_line)
        abort "You need to include a function for #{self} for validates_as_changelog_line?"
      end

      # https://stackoverflow.com/questions/25979364/ruby-regex-for-matching-brackets
      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
danger-changelog-0.7.0 lib/changelog/changelog_line/changelog_line.rb
danger-changelog-0.6.1 lib/changelog/changelog_line/changelog_line.rb