Class: WarningSigns::RubyCategoryMatcher
- Inherits:
-
Object
- Object
- WarningSigns::RubyCategoryMatcher
- Defined in:
- lib/warning_signs/ruby_category_matcher.rb
Instance Attribute Summary collapse
-
#except ⇒ Object
Returns the value of attribute except.
-
#only ⇒ Object
Returns the value of attribute only.
Instance Method Summary collapse
- #except_match?(category) ⇒ Boolean
-
#initialize(only: [], except: []) ⇒ RubyCategoryMatcher
constructor
A new instance of RubyCategoryMatcher.
- #match?(category) ⇒ Boolean
- #only_match?(category) ⇒ Boolean
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
#except ⇒ Object
Returns the value of attribute except.
3 4 5 |
# File 'lib/warning_signs/ruby_category_matcher.rb', line 3 def except @except end |
#only ⇒ Object
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
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
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
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 |