module DeviceMap module Keyword # Deletes all non-alphanumeric characters from the given keywords def self.normalize(keywords) keywords.map do |keyword| # HACK: BUILDER_DATA_SOURCE contains keywords like: # # # [Bb]lack.?[Bb]erry # blackberry 9650 # # # In such cases we want to replace patterns with simple keywords. keyword.downcase.gsub('[bb]', 'b').gsub(/[\W_]+/, '') end end # Concatenate all keywords together and skip duplicates def self.join(keywords) # HACK: This function handles the case when we want to concatenate all # keywords without duplication. # # # blackberry # blackberry 9700 # # normalize(keywords).reduce('') do |result, keyword| if keyword.include?(result) keyword else result.concat(keyword) end end end end end