module Mamiya::Util::LabelMatcher

Public Class Methods

parse_string_expr(str) click to toggle source
# File lib/mamiya/util/label_matcher.rb, line 4
def self.parse_string_expr(str)
  str.split(/\|/).map{ |_| _.split(/,/) }
end

Public Instance Methods

match?(*expressions) click to toggle source
# File lib/mamiya/util/label_matcher.rb, line 8
def match?(*expressions)
  labels = self.labels().map(&:to_s)

  if expressions.all? { |_| _.kind_of?(Symbol) || _.kind_of?(String) }
    return self.match?(expressions)
  end

  expressions.any? do |expression|
    case expression
    when Symbol, String
      labels.include?(expression.to_s)
    when Array
      if expression.any? { |_| _.kind_of?(Array) }
        self.match?(*expression)
      else
        expression.all? { |_| labels.include?(_.to_s) }
      end
    end
  end
end
Also aliased as: matches?
matches?(*expressions)
Alias for: match?