Class: WarningSigns::RubyCategoryMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/warning_signs/ruby_category_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(only: [], except: []) ⇒ RubyCategoryMatcher

Returns a new instance of RubyCategoryMatcher.



5
6
7
8
# File 'lib/warning_signs/ruby_category_matcher.rb', line 5

def initialize(only: [], except: [])
  @only = only.compact.map { _1.to_sym }
  @except = except.compact.map { _1.to_sym }
end

Instance Attribute Details

#exceptObject

Returns the value of attribute except.



3
4
5
# File 'lib/warning_signs/ruby_category_matcher.rb', line 3

def except
  @except
end

#onlyObject

Returns the value of attribute only.



3
4
5
# File 'lib/warning_signs/ruby_category_matcher.rb', line 3

def only
  @only
end

Instance Method Details

#except_match?(category) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
# File 'lib/warning_signs/ruby_category_matcher.rb', line 22

def except_match?(category)
  return true if except.empty?
  except.none? do |except_pattern|
    except_pattern === category&.to_sym
  end
end

#match?(category) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/warning_signs/ruby_category_matcher.rb', line 10

def match?(category)
  category = :blank if category.blank?
  only_match?(category) && except_match?(category)
end

#only_match?(category) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
# File 'lib/warning_signs/ruby_category_matcher.rb', line 15

def only_match?(category)
  return true if only.empty?
  only.any? do |only_pattern|
    only_pattern === category&.to_sym
  end
end