Sha256: d44aa7993c61687dda172264a48cc2f6f271a22a4433efb2343348333289c729

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 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

      def initialize(line)
        self.line = line
      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

4 entries across 4 versions & 1 rubygems

Version Path
danger-changelog-0.6.0 lib/changelog/changelog_line/changelog_line.rb
danger-changelog-0.5.0 lib/changelog/changelog_line/changelog_line.rb
danger-changelog-0.4.2 lib/changelog/changelog_line/changelog_line.rb
danger-changelog-0.4.1 lib/changelog/changelog_line/changelog_line.rb