Sha256: af81cc5c8a878fb62eda5426355210cb397a242dc462f2576507eaf0ee18876e

Contents?: true

Size: 646 Bytes

Versions: 5

Compression:

Stored size: 646 Bytes

Contents

module WarningSigns
  class OnlyExcept
    attr_accessor :only, :except

    def initialize(only: [], except: [])
      @only = only
      @except = except
    end

    def only_except_match?(message)
      only_match?(message) && except_match?(message)
    end

    def only_match?(message)
      return true if only.empty?
      only.any? do |only_pattern|
        only_pattern.match?(message)
      end
    end

    def except_match?(message)
      return true if except.empty?
      except.none? do |except_pattern|
        except_pattern.match?(message)
      end
    end

    def valid?
      except.empty? || only.empty?
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
warning_signs-0.7.2 lib/warning_signs/only_except.rb
warning_signs-0.7.1 lib/warning_signs/only_except.rb
warning_signs-0.7.0 lib/warning_signs/only_except.rb
warning_signs-0.6.1 lib/warning_signs/only_except.rb
warning_signs-0.6.0 lib/warning_signs/only_except.rb