Sha256: 75698f47ab0c13923676c690b3192467a97b847bdced7ecbedbae1d766b41c1c
Contents?: true
Size: 1.03 KB
Versions: 2
Compression:
Stored size: 1.03 KB
Contents
module Coconductor module Matchers class FieldAware < Licensee::Matchers::Exact include Coconductor::Matchers::Matcher def match return @match if defined? @match potential_matches.find do |code_of_conduct| file.content_normalized =~ regex_for(code_of_conduct) end end def confidence 100 end private FIELD_PLACEHOLDER = 'COCONDUCTOR_FIELD_COCONDUCTOR'.freeze FIELD_PLACEHOLDER_REGEX = /coconductor\\ field\\ coconductor/.freeze def regex_for(code_of_conduct) coc = code_of_conduct.dup coc.instance_variable_set '@content_normalized', nil coc.instance_variable_set '@content_without_title_and_version', nil field_regex = /#{Regexp.union(coc.fields.map(&:raw_text))}/i coc.content = coc.content.gsub(field_regex, FIELD_PLACEHOLDER) regex = Regexp.escape(coc.content_normalized) regex = regex.gsub(FIELD_PLACEHOLDER_REGEX, '([a-z ]+?)') Regexp.new(regex) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
coconductor-0.9.4 | lib/coconductor/matchers/field_aware.rb |
coconductor-0.9.3 | lib/coconductor/matchers/field_aware.rb |