class Consummo::KeywordHintEnricher

Public Class Methods

new(keywords:[]) click to toggle source
# File lib/consummo/enrichers/keyword_hint_enricher.rb, line 3
def initialize(keywords:[])
  @keywords = keywords
end

Public Instance Methods

enrich(item, keywords=[]) click to toggle source
# File lib/consummo/enrichers/keyword_hint_enricher.rb, line 7
def enrich(item, keywords=[])
  modified = item.title
  list = keywords.empty? ? @keywords : keywords

  for keyword in list do
    modified = make_replacements(modified, keyword)
  end
  {hinted_title: modified}
end

Private Instance Methods

make_replacements(text, keyword) click to toggle source
# File lib/consummo/enrichers/keyword_hint_enricher.rb, line 18
def make_replacements(text, keyword)
  return nil if text.blank?
  return text unless text.match(/#{keyword}/i)
  text.gsub(/(#{keyword})/i, '<strong>\1</strong>')
end