lib/zemanta/enhancer.rb in zemanta_client-0.0.4 vs lib/zemanta/enhancer.rb in zemanta_client-0.0.5

- old
+ new

@@ -1,7 +1,11 @@ module Zemanta class Enhancer + # Options: + # + # no_duplicates (default: false) - ensures links are used once + # def initialize(text, opts = {}) @text = text @opts = opts end @@ -13,11 +17,15 @@ private def enhance! words_to_anchor(@opts).each do |dictionary| link = "<a href=#{dictionary[:link]}>#{dictionary[:word]}</a>" - @text.gsub!(dictionary[:word], link) + if @opts[:no_duplicates] + @text.sub!(dictionary[:word], link) + else + @text.gsub!(dictionary[:word], link) + end end end def words_to_anchor(opts) suggest_markup(opts).links.map do |link| @@ -27,6 +35,6 @@ def suggest_markup(opts = {}) Markup.fetch(@text, opts) end end -end \ No newline at end of file +end