gotascii-crags 1.1.1 → 1.2.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/crags.gemspec +3 -3
- data/lib/crags.rb +1 -1
- data/lib/crags/searcher.rb +16 -11
- data/test/crags/searcher_test.rb +17 -16
- metadata +3 -3
data/crags.gemspec
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{crags}
|
3
|
-
s.version = "1.
|
3
|
+
s.version = "1.2.0"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Justin Marney"]
|
7
7
|
s.date = %q{2009-01-31}
|
8
8
|
s.description = %q{A library to help search across multiple craigslist locations.}
|
9
|
-
s.email = %q{
|
9
|
+
s.email = %q{gotascii@gmail.com}
|
10
10
|
s.extra_rdoc_files = ["History.txt", "README.txt", "lib/js/client.html"]
|
11
11
|
s.files = [".gitignore", "History.txt", "Manifest.txt", "README.txt", "Rakefile", "crags.gemspec", "lib/crags.rb", "lib/crags/fetch.rb", "lib/crags/proxy.rb", "lib/crags/runner.rb", "lib/crags/searcher.rb", "lib/js/client.html", "tasks/ann.rake", "tasks/bones.rake", "tasks/gem.rake", "tasks/git.rake", "tasks/manifest.rake", "tasks/notes.rake", "tasks/post_load.rake", "tasks/rdoc.rake", "tasks/rubyforge.rake", "tasks/setup.rb", "tasks/spec.rake", "tasks/svn.rake", "tasks/test.rake", "test/crags/fetch_test.rb", "test/crags/proxy_test.rb", "test/crags/runner_test.rb", "test/crags/searcher_test.rb", "test/test_helper.rb"]
|
12
12
|
s.has_rdoc = true
|
13
|
-
s.homepage = %q{http://github.com/
|
13
|
+
s.homepage = %q{http://github.com/gotascii/crags}
|
14
14
|
s.rdoc_options = ["--main", "README.txt"]
|
15
15
|
s.require_paths = ["lib"]
|
16
16
|
s.rubyforge_project = %q{crags}
|
data/lib/crags.rb
CHANGED
data/lib/crags/searcher.rb
CHANGED
@@ -2,6 +2,10 @@ module Crags
|
|
2
2
|
module Searcher
|
3
3
|
include Fetch
|
4
4
|
|
5
|
+
def strip_http(url)
|
6
|
+
url.gsub(/http\:\/\/(.*)\//,'\1')
|
7
|
+
end
|
8
|
+
|
5
9
|
def location_doc
|
6
10
|
fetch_doc("http://geo.craigslist.org/iso/us")
|
7
11
|
end
|
@@ -11,7 +15,7 @@ module Crags
|
|
11
15
|
end
|
12
16
|
|
13
17
|
def locations
|
14
|
-
location_links.collect{|link| link["href"]
|
18
|
+
location_links.collect{|link| strip_http(link["href"]) }
|
15
19
|
end
|
16
20
|
|
17
21
|
def categories
|
@@ -32,22 +36,23 @@ module Crags
|
|
32
36
|
end
|
33
37
|
|
34
38
|
def items(doc)
|
35
|
-
doc.search("item")
|
39
|
+
doc.search("item").collect do |item|
|
40
|
+
hashify(item)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def hashify(item)
|
45
|
+
title = item.at("title").inner_text
|
46
|
+
url = strip_http(item["rdf:about"])
|
47
|
+
{:title => title, :url => url}
|
36
48
|
end
|
37
49
|
|
38
50
|
def search_location(keyword, loc, category = 'sss', &block)
|
39
51
|
doc = fetch_doc("http://#{loc}/search/#{category}?query=#{keyword}&format=rss")
|
40
52
|
items(doc).collect do |item|
|
41
|
-
|
42
|
-
|
43
|
-
link
|
53
|
+
yield item if block_given?
|
54
|
+
item
|
44
55
|
end
|
45
56
|
end
|
46
|
-
|
47
|
-
def create_link(item)
|
48
|
-
link = item["rdf:about"]
|
49
|
-
title = item.at("title").inner_text
|
50
|
-
"<a href=\"#{link}\">#{title}</a>"
|
51
|
-
end
|
52
57
|
end
|
53
58
|
end
|
data/test/crags/searcher_test.rb
CHANGED
@@ -7,6 +7,11 @@ context "Searcher with stubbed fetch doc" do
|
|
7
7
|
stubs(:fetch_doc)
|
8
8
|
end
|
9
9
|
|
10
|
+
specify "strip_http should remove http:// and trailing /" do
|
11
|
+
url = "http://omg/"
|
12
|
+
strip_http(url).should == "omg"
|
13
|
+
end
|
14
|
+
|
10
15
|
specify "location doc should fetch doc at location url" do
|
11
16
|
expects(:fetch_doc).with("http://geo.craigslist.org/iso/us").returns("doc")
|
12
17
|
location_doc.should == "doc"
|
@@ -51,28 +56,24 @@ context "Searcher with stubbed fetch doc" do
|
|
51
56
|
search_location("keyword", "url")
|
52
57
|
end
|
53
58
|
|
54
|
-
specify "search location should create
|
59
|
+
specify "search location should create return items" do
|
55
60
|
items = [1,2,3]
|
56
61
|
expects(:items).returns(items)
|
57
|
-
|
58
|
-
expects(:create_link).with(i).returns("omg#{i}")
|
59
|
-
end
|
60
|
-
search_location("keyword", "url").should == ['omg1','omg2','omg3']
|
62
|
+
search_location("keyword", "url").should == items
|
61
63
|
end
|
62
64
|
|
63
|
-
specify "
|
64
|
-
|
65
|
-
item
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
|
70
|
-
create_link(item).should == "<a href=\"link\">text</a>"
|
65
|
+
specify "items should get all item elements from doc" do
|
66
|
+
item = stub
|
67
|
+
stubs(:hashify).with(item).returns(1)
|
68
|
+
doc = mock { expects(:search).with("item").returns([item]) }
|
69
|
+
items(doc).should == [1]
|
71
70
|
end
|
72
71
|
|
73
|
-
specify "items should
|
74
|
-
|
75
|
-
|
72
|
+
specify "items should hashify all item elements from doc" do
|
73
|
+
item = stub
|
74
|
+
expects(:hashify).with(item).returns(1)
|
75
|
+
doc = stub { stubs(:search).returns([item]) }
|
76
|
+
items(doc).should == [1]
|
76
77
|
end
|
77
78
|
|
78
79
|
specify "categories should fetch doc the main sfbay page" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotascii-crags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Marney
|
@@ -14,7 +14,7 @@ default_executable:
|
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: A library to help search across multiple craigslist locations.
|
17
|
-
email:
|
17
|
+
email: gotascii@gmail.com
|
18
18
|
executables: []
|
19
19
|
|
20
20
|
extensions: []
|
@@ -55,7 +55,7 @@ files:
|
|
55
55
|
- test/crags/searcher_test.rb
|
56
56
|
- test/test_helper.rb
|
57
57
|
has_rdoc: true
|
58
|
-
homepage: http://github.com/
|
58
|
+
homepage: http://github.com/gotascii/crags
|
59
59
|
post_install_message:
|
60
60
|
rdoc_options:
|
61
61
|
- --main
|