Module: Mamiya::Util::LabelMatcher

Included in:
Agent, Simple
Defined in:
lib/mamiya/util/label_matcher.rb

Defined Under Namespace

Classes: Simple

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_string_expr(str) ⇒ Object



4
5
6
# File 'lib/mamiya/util/label_matcher.rb', line 4

def self.parse_string_expr(str)
  str.split(/\|/).map{ |_| _.split(/,/) }
end

Instance Method Details

#match?(*expressions) ⇒ Boolean Also known as: matches?

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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