lib/eco/data/fuzzy_match/string_helpers.rb in eco-helpers-2.0.19 vs lib/eco/data/fuzzy_match/string_helpers.rb in eco-helpers-2.0.21

- old
+ new

@@ -15,11 +15,11 @@ end def get_words(str, normalized: false) return [] unless str str = normalize_string(str) unless normalized - str.scan(/[a-zA-Z'-]+/) + str.scan(/[a-zA-Z'-]+/).compact end # Keeps the start order of the `words` and consecutive `words` together/consecutive. # @param str [String] the input string with the words. # @param range [Integer, Range] determine the lenght of the generated values. @@ -59,9 +59,22 @@ end def no_blanks(str) return nil unless str && str.is_a?(String) str.tr(' ', '') + end + + # Deletes the words of `str1` and `str2` that match + # @return [Array<String>] pair of words. + def remove_matching_words(str1, str2, normalized: false) + unless normalized + str1 = normalize_string(str1) + str2 = normalize_string(str2) + end + return [str1, str2] if !str1 || !str2 || str1.empty? || str2.empty? + ws1 = get_words(str1) + ws2 = get_words(str2) + [(ws1 - ws2).join(" "), (ws2 - ws1).join(" ")] end end end end