keyword_prospector 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,140 @@
1
+ #
2
+ # (C) 2008 Los Angeles Times
3
+ #
4
+ require File.dirname(__FILE__) + '/spec_helper'
5
+ require 'match'
6
+
7
+ describe Match do
8
+ describe "spaceship operator" do
9
+ it "returns -1 when start position of other is greater than start position of self" do
10
+ match = Match.new(:dont_care, 1, 5)
11
+ other_matches = [Match.new(:dont_care, 5, 7),
12
+ Match.new(:dont_care, 2, 7),
13
+ Match.new(:dont_care, 2, 3)]
14
+
15
+ other_matches.each do |m|
16
+ (match <=> m).should == -1
17
+ end
18
+ end
19
+
20
+ it "returns -1 when start positions are equal and end position of other is greater than end position of self" do
21
+ match = Match.new(:dont_care, 1, 5)
22
+ other_matches = [Match.new(:dont_care, 1, 7),
23
+ Match.new(:dont_care, 1, 9)]
24
+
25
+ other_matches.each do |m|
26
+ (match <=> m).should == -1
27
+ end
28
+ end
29
+
30
+ it "returns 0 when start position and end position are the same" do
31
+ [[0, 7], [1, 13], [7, 9]].each do |values|
32
+ match1 = Match.new(:dont_care, values[0], values[1])
33
+ match2 = Match.new(:dont_care, values[0], values[1])
34
+
35
+ (match1 <=> match2).should == 0
36
+ end
37
+ end
38
+
39
+ it "returns 1 when start position of other is less than start position of self" do
40
+ match = Match.new(:dont_care, 5, 9)
41
+ other_matches = [Match.new(:dont_care, 1, 4),
42
+ Match.new(:dont_care, 2, 6),
43
+ Match.new(:dont_care, 4, 11)]
44
+
45
+ other_matches.each do |m|
46
+ (match <=> m).should == 1
47
+ end
48
+ end
49
+
50
+ it "returns 1 when start positions are equal and end position of other is less than end position of self" do
51
+ match = Match.new(:dont_care, 5, 9)
52
+ other_matches = [Match.new(:dont_care, 5, 6),
53
+ Match.new(:dont_care, 5, 8)]
54
+
55
+ other_matches.each do |m|
56
+ (match <=> m).should == 1
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "accessors" do
62
+ before(:each) do
63
+ @match = Match.new(:first, :second, :third, :fourth)
64
+ end
65
+
66
+ it "keyword, start, and end should be assigned correctly" do
67
+ @match.keyword.should == :first
68
+ @match.start_idx.should == :second
69
+ @match.end_idx.should == :third
70
+ @match.output.should == :fourth
71
+ end
72
+ end
73
+
74
+ describe "overlap?" do
75
+ it "should return false when there is no overlap" do
76
+ match1 = Match.new("foo", 1, 4)
77
+ match2 = Match.new("bar", 7, 10)
78
+
79
+ should_not_overlap(match1, match2)
80
+ end
81
+
82
+ it "should return true when there is an overlap" do
83
+ match1 = Match.new("foo", 1, 4)
84
+ match2 = Match.new("bar", 2, 10)
85
+
86
+ should_overlap(match1, match2)
87
+ end
88
+
89
+ it "should return false when matches are consecutive" do
90
+ match1 = Match.new("foo", 1, 4)
91
+ match2 = Match.new("bar", 4, 10)
92
+
93
+ should_not_overlap(match1, match2)
94
+ end
95
+
96
+ it "should return true when overlap is one character" do
97
+ match1 = Match.new("foo", 1, 4)
98
+ match2 = Match.new("bar", 3, 10)
99
+
100
+ should_overlap(match1, match2)
101
+ end
102
+
103
+ def should_not_overlap(a, b)
104
+ a.overlap?(b).should == false
105
+ b.overlap?(a).should == false
106
+ end
107
+
108
+ def should_overlap(a, b)
109
+ a.overlap?(b).should == true
110
+ b.overlap?(a).should == true
111
+ end
112
+ end
113
+
114
+ describe "length" do
115
+ it "should return the difference between start and end indices" do
116
+ [[1, 4], [2, 7]].each do |start_idx, end_idx|
117
+ Match.new("don't care", start_idx, end_idx).length.should ==
118
+ end_idx - start_idx
119
+ end
120
+ end
121
+ end
122
+
123
+ describe "equality" do
124
+ it "should be true if matches occupy same space regardless of keyword" do
125
+ m1 = Match.new("foo", 1, 7)
126
+ m2 = Match.new("bar", 1, 7)
127
+
128
+ m1.should == m2
129
+ end
130
+
131
+ it "should be false if matches don't occupy same space" do
132
+ m1 = Match.new("foo", 1, 7)
133
+ m2 = Match.new("bar", 2, 7)
134
+ m3 = Match.new("bar", 1, 6)
135
+
136
+ m1.should_not == m2
137
+ m1.should_not == m3
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,58 @@
1
+ #
2
+ # (C) 2008 Los Angeles Times
3
+ #
4
+ require File.dirname(__FILE__) + '/spec_helper'
5
+ require 'search_and_replace'
6
+
7
+ describe SearchAndReplace do
8
+ before(:each) do
9
+ @sar = SearchAndReplace.new
10
+ end
11
+
12
+ describe :add_replacement do
13
+ it "should take an original and a replacement" do
14
+ @sar.add_replacement("original", "replacement")
15
+ end
16
+ end
17
+
18
+ describe :replace_text do
19
+ before(:each) do
20
+ @sar.add_replacement("original", "replacement")
21
+ @sar.add_replacement("foo", "bar")
22
+ end
23
+
24
+ it "should replace text" do
25
+ @sar.replace_text("original").should == "replacement"
26
+ end
27
+
28
+ it "should replace text at the beginning of the string" do
29
+ @sar.replace_text("original is me").should == "replacement is me"
30
+ end
31
+
32
+ it "should replace text in the middle of the string" do
33
+ @sar.replace_text("is original me").should == "is replacement me"
34
+ end
35
+
36
+ it "should replace text at the end of the string" do
37
+ @sar.replace_text("me is original").should == "me is replacement"
38
+ end
39
+
40
+ it "should replace multiple instances of the same word" do
41
+ @sar.replace_text("original original original").should == "replacement replacement replacement"
42
+ end
43
+
44
+ it "should replace multiple words" do
45
+ @sar.replace_text("original foo original foo").should == "replacement bar replacement bar"
46
+ end
47
+
48
+ it "should have no trouble with html code" do
49
+ link = '<a href="http://travel.latimes.com/destinations/bar-url">bar</a>'
50
+ @sar.add_replacement(link, "bar")
51
+ @sar.replace_text(link).should == "bar"
52
+ end
53
+
54
+ it "respects word boundaries" do
55
+ @sar.replace_text("football").should == "football"
56
+ end
57
+ end
58
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,10 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'keyword_prospector'
@@ -0,0 +1,128 @@
1
+ #
2
+ # (C) 2008 Los Angeles Times
3
+ #
4
+ require File.dirname(__FILE__) + '/spec_helper'
5
+ require 'state'
6
+
7
+ describe State do
8
+ before(:each) do
9
+ @state = State.new(:char)
10
+ end
11
+
12
+ describe "initializer" do
13
+ it "should increment id for each new object" do
14
+ state1 = State.new(:char)
15
+ state2 = State.new(:char)
16
+ state3 = State.new(:char)
17
+
18
+ state2.id.should > state1.id
19
+
20
+ state3.id.should > state2.id
21
+ end
22
+
23
+ it "should initialize char with the value passed" do
24
+ state = State.new(:value)
25
+ state.char.should == :value
26
+ end
27
+ end
28
+
29
+ describe "should have accessor" do
30
+ [:fail, :fail_increment, :output, :depth, :keyword].each do |method|
31
+ it method do
32
+ @state.send(method.to_s + "=", :any_object)
33
+ @state.send(method.to_s).should == :any_object
34
+ end
35
+ end
36
+ end
37
+
38
+ describe "children" do
39
+ it "should initially be nil" do
40
+ @state[:char].should == nil
41
+ end
42
+
43
+ it "should be assignable" do
44
+ @state[:char] = :value
45
+ @state[:char].should == :value
46
+ end
47
+
48
+ it "should have their keys available" do
49
+ keys = [?a, ?b, ?c]
50
+ keys.each {|key| @state[key] = :dont_care}
51
+
52
+ @state.keys.sort.should == keys
53
+ end
54
+
55
+ it "should have their values available" do
56
+ values = [?a, ?b, ?c]
57
+
58
+ values.size.times do |time|
59
+ @state[time] = values[time]
60
+ end
61
+
62
+ @state.values.sort.should == values
63
+ end
64
+ end
65
+
66
+ describe "insert_next_state" do
67
+ it "should create a new state initialized with the value provided" do
68
+ child_state = State.new(:char)
69
+ State.should_receive(:new).with(:char, 1).and_return(child_state)
70
+
71
+ @state.insert_next_state(:char)
72
+
73
+ @state[:char].should be_eql(child_state)
74
+ end
75
+
76
+ it "should not create a new child state if one already exists" do
77
+ child_state = State.new(:char)
78
+ State.should_receive(:new).exactly(1).times.with(:char, 1).
79
+ and_return(child_state)
80
+
81
+ @state.insert_next_state(:char)
82
+ @state.insert_next_state(:char)
83
+
84
+ @state[:char].should be_eql(child_state)
85
+ end
86
+ end
87
+
88
+ describe "transition" do
89
+ it "should return next state selected by char" do
90
+ @state[:char] = :next_state
91
+ @state.transition(:char).should == :next_state
92
+ end
93
+
94
+ it "to self should increment start position and set end position to equal start" do
95
+ @state[:char] = @state
96
+ position = Object.new
97
+ position.should_receive(:begin).and_return(1)
98
+ position.should_receive(:begin=).with(2)
99
+ position.should_receive(:end=).with(2)
100
+
101
+ @state.transition(:char, position)
102
+ end
103
+
104
+ it "should increment end position by one if state is found" do
105
+ position = Object.new
106
+ position.should_receive(:end).and_return(42)
107
+ position.should_receive(:end=).with(43)
108
+
109
+ @state[:char] = :next_state
110
+
111
+ @state.transition(:char, position)
112
+ end
113
+
114
+ describe "failures" do
115
+ before(:each) do
116
+ @fail_state = State.new(:dont_care)
117
+ @state.fail = @fail_state
118
+ end
119
+
120
+ it "should transition from fail state if next state doesn't exist" do
121
+ @fail_state.should_receive(:transition).with(:char).
122
+ and_return(:fail_state_transition)
123
+
124
+ @state.transition(:char).should == :fail_state_transition
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
@@ -0,0 +1,141 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ keyword_prospector
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1>keyword_prospector</h1>
34
+ <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/keyword_prospector"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="http://rubyforge.org/projects/keyword_prospector" class="numbers">0.8.0</a>
37
+ </div>
38
+ <h1>&#x2192; &#8216;keyword_prospector&#8217;</h1>
39
+
40
+
41
+ <h2>What</h2>
42
+
43
+
44
+ <h2>Installing</h2>
45
+
46
+
47
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">keyword_prospector</span></pre></p>
48
+
49
+
50
+ <h2>The basics</h2>
51
+
52
+
53
+ <h2>Demonstration of usage</h2>
54
+
55
+
56
+ <h2>Forum</h2>
57
+
58
+
59
+ <p><a href="http://groups.google.com/group/keyword_prospector">http://groups.google.com/group/keyword_prospector</a></p>
60
+
61
+
62
+ <p><span class="caps">TODO</span> &#8211; create Google Group &#8211; keyword_prospector</p>
63
+
64
+
65
+ <h2>How to submit patches</h2>
66
+
67
+
68
+ <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
69
+
70
+
71
+ <p><span class="caps">TODO</span> &#8211; pick <span class="caps">SVN</span> or Git instructions</p>
72
+
73
+
74
+ <p>The trunk repository is <code>svn://rubyforge.org/var/svn/keyword_prospector/trunk</code> for anonymous access.</p>
75
+
76
+
77
+ <p><span class="caps">OOOORRRR</span></p>
78
+
79
+
80
+ <p>You can fetch the source from either:</p>
81
+
82
+
83
+ <ul>
84
+ <li>rubyforge: <span class="caps">MISSING IN ACTION</span></li>
85
+ </ul>
86
+
87
+
88
+ <p><span class="caps">TODO</span> &#8211; You can not created a RubyForge project, OR have not run <code>rubyforge config</code>
89
+ yet to refresh your local rubyforge data with this projects&#8217; id information.</p>
90
+
91
+
92
+ <p>When you do this, this message will magically disappear!</p>
93
+
94
+
95
+ <p>Or you can hack website/index.txt and make it all go away!!</p>
96
+
97
+
98
+ <ul>
99
+ <li>github: <a href="http://github.com/GITHUB_USERNAME/keyword_prospector/tree/master">http://github.com/GITHUB_USERNAME/keyword_prospector/tree/master</a></li>
100
+ </ul>
101
+
102
+
103
+ <pre>git clone git://github.com/GITHUB_USERNAME/keyword_prospector.git</pre>
104
+
105
+ <p><span class="caps">TODO</span> &#8211; add &#8220;github_username: username&#8221; to ~/.rubyforge/user-config.yml and newgem will reuse it for future projects.</p>
106
+
107
+
108
+ <ul>
109
+ <li>gitorious: <a href="git://gitorious.org/keyword_prospector/mainline.git">git://gitorious.org/keyword_prospector/mainline.git</a></li>
110
+ </ul>
111
+
112
+
113
+ <pre>git clone git://gitorious.org/keyword_prospector/mainline.git</pre>
114
+
115
+ <h3>Build and test instructions</h3>
116
+
117
+
118
+ <pre>cd keyword_prospector
119
+ rake test
120
+ rake install_gem</pre>
121
+
122
+ <h2>License</h2>
123
+
124
+
125
+ <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
126
+
127
+
128
+ <h2>Contact</h2>
129
+
130
+
131
+ <p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/keyword_prospector">forum</a></p>
132
+ <p class="coda">
133
+ <a href="FIXME email">FIXME full name</a>, 11th August 2008<br>
134
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
135
+ </p>
136
+ </div>
137
+
138
+ <!-- insert site tracking codes here, like Google Urchin -->
139
+
140
+ </body>
141
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,83 @@
1
+ h1. keyword_prospector
2
+
3
+ h1. &#x2192; 'keyword_prospector'
4
+
5
+
6
+ h2. What
7
+
8
+
9
+ h2. Installing
10
+
11
+ <pre syntax="ruby">sudo gem install keyword_prospector</pre>
12
+
13
+ h2. The basics
14
+
15
+
16
+ h2. Demonstration of usage
17
+
18
+
19
+
20
+ h2. Forum
21
+
22
+ "http://groups.google.com/group/keyword_prospector":http://groups.google.com/group/keyword_prospector
23
+
24
+ TODO - create Google Group - keyword_prospector
25
+
26
+ h2. How to submit patches
27
+
28
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
29
+
30
+ TODO - pick SVN or Git instructions
31
+
32
+ The trunk repository is <code>svn://rubyforge.org/var/svn/keyword_prospector/trunk</code> for anonymous access.
33
+
34
+ OOOORRRR
35
+
36
+ You can fetch the source from either:
37
+
38
+ <% if rubyforge_project_id %>
39
+
40
+ * rubyforge: "http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>":http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>
41
+
42
+ <pre>git clone git://rubyforge.org/keyword_prospector.git</pre>
43
+
44
+ <% else %>
45
+
46
+ * rubyforge: MISSING IN ACTION
47
+
48
+ TODO - You can not created a RubyForge project, OR have not run <code>rubyforge config</code>
49
+ yet to refresh your local rubyforge data with this projects' id information.
50
+
51
+ When you do this, this message will magically disappear!
52
+
53
+ Or you can hack website/index.txt and make it all go away!!
54
+
55
+ <% end %>
56
+
57
+ * github: "http://github.com/GITHUB_USERNAME/keyword_prospector/tree/master":http://github.com/GITHUB_USERNAME/keyword_prospector/tree/master
58
+
59
+ <pre>git clone git://github.com/GITHUB_USERNAME/keyword_prospector.git</pre>
60
+
61
+
62
+ TODO - add "github_username: username" to ~/.rubyforge/user-config.yml and newgem will reuse it for future projects.
63
+
64
+
65
+ * gitorious: "git://gitorious.org/keyword_prospector/mainline.git":git://gitorious.org/keyword_prospector/mainline.git
66
+
67
+ <pre>git clone git://gitorious.org/keyword_prospector/mainline.git</pre>
68
+
69
+ h3. Build and test instructions
70
+
71
+ <pre>cd keyword_prospector
72
+ rake test
73
+ rake install_gem</pre>
74
+
75
+
76
+ h2. License
77
+
78
+ This code is free to use under the terms of the MIT license.
79
+
80
+ h2. Contact
81
+
82
+ Comments are welcome. Send an email to "FIXME full name":mailto:FIXME email via the "forum":http://groups.google.com/group/keyword_prospector
83
+