zemanta_client 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -49,6 +49,10 @@ Two use cases are implemented:
49
49
  ```ruby
50
50
  Zemanta::Enhancer.new(text, opts = {}).enhance
51
51
  ```
52
+
53
+ Options:
54
+ no_duplicates (default: false) - ensures links are used once
55
+
52
56
 
53
57
  It will fetch suggest_markup data for given text and for every returned link it will wrap the keyword with this link.
54
58
  Then it will return the updated text.
@@ -91,7 +95,8 @@ end
91
95
 
92
96
  ## Changelog
93
97
 
94
- 0.0.4 - fixed yajl require in gemspec
98
+ 0.0.5 - Added #no_duplicates option to Enhancer
99
+ 0.0.4 - Fixed yajl require in gemspec
95
100
  0.0.3 - Added Enhancer class, used yajl for json parsing, changed external gem api.
96
101
  0.0.2 - Got rid of autoloads.
97
102
  0.0.1 - Initial release. Support for suggest_markup method and caching.
@@ -1,5 +1,9 @@
1
1
  module Zemanta
2
2
  class Enhancer
3
+ # Options:
4
+ #
5
+ # no_duplicates (default: false) - ensures links are used once
6
+ #
3
7
  def initialize(text, opts = {})
4
8
  @text = text
5
9
  @opts = opts
@@ -15,7 +19,11 @@ module Zemanta
15
19
  def enhance!
16
20
  words_to_anchor(@opts).each do |dictionary|
17
21
  link = "<a href=#{dictionary[:link]}>#{dictionary[:word]}</a>"
18
- @text.gsub!(dictionary[:word], link)
22
+ if @opts[:no_duplicates]
23
+ @text.sub!(dictionary[:word], link)
24
+ else
25
+ @text.gsub!(dictionary[:word], link)
26
+ end
19
27
  end
20
28
  end
21
29
 
@@ -29,4 +37,4 @@ module Zemanta
29
37
  Markup.fetch(@text, opts)
30
38
  end
31
39
  end
32
- end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Zemanta
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -13,5 +13,14 @@ describe Zemanta::Enhancer do
13
13
  stub_zemanta_enhancer!
14
14
  Zemanta::Enhancer.new(input).enhance.scan('<a').should have(2).elements
15
15
  end
16
+
17
+ describe "no_duplicates option" do
18
+ it "doesn't use the same link multiple times" do
19
+ stub_zemanta_enhancer!
20
+ input = "I like Machu Pichu. Machu Pichu? Yeah, Machu Pichu"
21
+ output = Zemanta::Enhancer.new(input, no_duplicates: true).enhance
22
+ output.scan('<a').should have(1).elements
23
+ end
24
+ end
16
25
  end
17
- end
26
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zemanta_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-19 00:00:00.000000000 Z
12
+ date: 2013-06-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus