highscore 0.3.2 → 0.4.0

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/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.4.0 / 2012-02-04
2
+
3
+ * monkey-patched String to have a keywords method on it that takes the same arguments as Highscore::Content.new
4
+ * merge multiple Keywords objects to one (e.g. from different sources)
5
+
1
6
  == 0.3.2 / 2012-01-27
2
7
 
3
8
  * use custom lists of ignored words (blacklist), fallback to a default list
data/README.md CHANGED
@@ -1,12 +1,15 @@
1
1
  highscore
2
2
  ===========
3
3
 
4
- Rank keywords in long texts.
4
+ Find and rank keywords in long texts.
5
5
 
6
6
  Features
7
7
  --------
8
8
 
9
9
  * configureable to rank different types of words different (uppercase, long words, etc.)
10
+ * directly get keywords from String objects
11
+ * blacklist words via a plain text file, String or an Array of words
12
+ * merge together Keywords from multiple sources
10
13
 
11
14
  Examples
12
15
  --------
@@ -28,6 +31,13 @@ Examples
28
31
  keyword.weight # => rank weight (float)
29
32
  end
30
33
 
34
+ # you could simply just use a string
35
+ text = "foo bar".keywords(blacklist) do
36
+ set :multiplier, 10
37
+ end
38
+
39
+ text.keywords
40
+
31
41
 
32
42
  Using a custom blacklist to ignore keywords
33
43
  -------------------------------------------
@@ -67,12 +67,31 @@ module Highscore
67
67
  # Enumerable
68
68
  #
69
69
  def each &block
70
- @keywords.each {|keyword| keyword.call(keyword)}
70
+ @keywords.each {|keyword| yield keyword[1] }
71
71
  end
72
72
 
73
73
  # number of Keywords given
74
74
  def length
75
75
  @keywords.length
76
76
  end
77
+
78
+ # get the keyword with the highest rank
79
+ def first
80
+ sort.first
81
+ end
82
+
83
+ # get the keyword with the lowest rank
84
+ def last
85
+ sort.reverse.first
86
+ end
87
+
88
+ # merge in another keyword list, operates on self
89
+ def merge!(other)
90
+ other.each do |keyword|
91
+ self << keyword
92
+ end
93
+
94
+ self
95
+ end
77
96
  end
78
97
  end
@@ -0,0 +1,18 @@
1
+ # monkey patch to define a keywords method on arbitrary strings
2
+ #
3
+ class String
4
+
5
+ # get keywords from the string
6
+ #
7
+ def keywords(blacklist = nil, &block)
8
+ content = Highscore::Content.new(self, blacklist)
9
+
10
+ if block_given?
11
+ content.configure do
12
+ content.instance_eval(&block)
13
+ end
14
+ end
15
+
16
+ content.keywords
17
+ end
18
+ end
@@ -16,6 +16,20 @@ class TestKeywords < Test::Unit::TestCase
16
16
  assert Highscore::Keywords.new.length == 0
17
17
  end
18
18
 
19
+ def test_each
20
+ @keywords.each do |x|
21
+ assert(x.instance_of?(Highscore::Keyword), "should contain Highscore::Keyword instances, is #{x.class}")
22
+ end
23
+ end
24
+
25
+ def test_first
26
+ assert_equal 'the', @keywords.first.text
27
+ end
28
+
29
+ def test_last
30
+ assert_equal 'Highscore', @keywords.last.text
31
+ end
32
+
19
33
  def test_rank
20
34
  assert @keywords.length == 4
21
35
 
@@ -47,4 +61,14 @@ class TestKeywords < Test::Unit::TestCase
47
61
  def test_top_empty
48
62
  assert_equal [], Highscore::Keywords.new.top(0)
49
63
  end
64
+
65
+ def test_merge!
66
+ other = Highscore::Keywords.new
67
+ other << Highscore::Keyword.new('Ruby', 100.3)
68
+
69
+ @keywords.merge!(other)
70
+
71
+ assert_equal 102.3, @keywords.first.weight
72
+ assert_equal 'Ruby', @keywords.first.text
73
+ end
50
74
  end
@@ -0,0 +1,38 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), %w{.. .. lib}))
2
+ require 'highscore'
3
+ require "test/unit"
4
+
5
+ class TestString < Test::Unit::TestCase
6
+ def setup
7
+ blacklist_file = File.join(File.dirname(__FILE__), %w{.. fixtures blacklist.txt})
8
+ @blacklist = Highscore::Blacklist.load_file(blacklist_file)
9
+ end
10
+
11
+ def test_init
12
+ keywords = "".keywords
13
+ assert_equal 0, keywords.length
14
+ end
15
+
16
+ def test_default_blacklist
17
+ keywords = "the Ruby Ruby Ruby Hacker".keywords
18
+ assert_equal 2, keywords.length
19
+ end
20
+
21
+ def test_custom_blacklist
22
+ keywords = "this is the test Ruby Ruby Ruby Hacker".keywords(@blacklist)
23
+
24
+ assert_equal 2, keywords.length
25
+
26
+ assert_equal 9, keywords.first.weight
27
+ assert_equal 3, keywords.last.weight
28
+ end
29
+
30
+ def test_with_block
31
+ keywords = "this is the test Ruby Ruby Ruby Hacker".keywords(@blacklist) do
32
+ set :multiplier, 10
33
+ end
34
+
35
+ assert_equal 90, keywords.first.weight
36
+ assert_equal 30, keywords.last.weight
37
+ end
38
+ end
data/version.txt CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.4.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: highscore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-27 00:00:00.000000000 Z
12
+ date: 2012-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bones
16
- requirement: &70200855600060 !ruby/object:Gem::Requirement
16
+ requirement: &70220913110960 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,8 +21,8 @@ dependencies:
21
21
  version: 3.7.3
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70200855600060
25
- description: Rank keywords in long texts.
24
+ version_requirements: *70220913110960
25
+ description: Find and rank keywords in long texts.
26
26
  email: liebler.dominik@googlemail.com
27
27
  executables:
28
28
  - highscore
@@ -45,11 +45,13 @@ files:
45
45
  - lib/highscore/content.rb
46
46
  - lib/highscore/keyword.rb
47
47
  - lib/highscore/keywords.rb
48
+ - lib/highscore/string.rb
48
49
  - test/fixtures/blacklist.txt
49
50
  - test/highscore/test_blacklist.rb
50
51
  - test/highscore/test_content.rb
51
52
  - test/highscore/test_keyword.rb
52
53
  - test/highscore/test_keywords.rb
54
+ - test/highscore/test_string.rb
53
55
  - test/test_highscore.rb
54
56
  - version.txt
55
57
  homepage: http://thewebdev.de
@@ -77,10 +79,11 @@ rubyforge_project: highscore
77
79
  rubygems_version: 1.8.11
78
80
  signing_key:
79
81
  specification_version: 3
80
- summary: Rank keywords in long texts.
82
+ summary: Find and rank keywords in long texts.
81
83
  test_files:
82
84
  - test/highscore/test_blacklist.rb
83
85
  - test/highscore/test_content.rb
84
86
  - test/highscore/test_keyword.rb
85
87
  - test/highscore/test_keywords.rb
88
+ - test/highscore/test_string.rb
86
89
  - test/test_highscore.rb