module KeywordReplacer::Core::InstanceMethods

Attributes

custom_class[R]
keywords[R]
keywords_matcher[R]
max_matches[R]
options[RW]

Private Instance Methods

replace_keywords(target) click to toggle source
# File lib/keyword_replacer/core.rb, line 46
def replace_keywords(target)
  target.gsub(keywords_matcher) do |match|
    if options[match] >= 2 || options.sum { |_, v| v } >= max_matches
      match
    else
      options[match] += 1
      keyword_link = keywords_with_links[match.downcase]
      "<a target='_blank' class='#{custom_class}' href='#{keyword_link}' >#{match}</a>"
    end
  end
end