class Sanctify::MatcherList
Constants
- DEFAULT_MATCHERS
Public Class Methods
new(custom_matchers:, disabled_matchers:)
click to toggle source
# File lib/sanctify/matcher_list.rb, line 6 def initialize(custom_matchers:, disabled_matchers:) # initialize Array in case users have that field blank @disabled_matchers = disabled_matchers || [] @custom_matchers = custom_matchers || [] # Create Matcher objects out of const. @matchers = DEFAULT_MATCHERS.map do |obj| disabled = @disabled_matchers.include?(obj[:id]) Matcher.new(obj[:id], obj[:description], obj[:regex], disabled: disabled) end initialize_custom_matchers! end
Public Instance Methods
add(id, description, regex)
click to toggle source
# File lib/sanctify/matcher_list.rb, line 19 def add(id, description, regex) if description.empty? raise ParserError, "Description must exist and be greater length than zero" end unless regex.is_a? Regexp raise ParserError, "Regex must be of type Regexp" end @matchers << Matcher.new(id, description, regex) end
each(&blk)
click to toggle source
# File lib/sanctify/matcher_list.rb, line 31 def each(&blk) @matchers.each &blk end
initialize_custom_matchers!()
click to toggle source
# File lib/sanctify/matcher_list.rb, line 35 def initialize_custom_matchers! if @custom_matchers.any? @custom_matchers.each do |cust| if cust['description'] && cust['regex'] add(cust['id'], cust['description'], Regexp.new(cust['regex'])) else raise ParserError, "Improperly configured custom matcher: #{cust}. Must include 'description' and 'regex'" end end end end