crags 2.1.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gem "curb"
4
- gem "hpricot"
4
+ gem "nokogiri"
5
5
 
6
6
  group :test do
7
7
  gem "rspec"
data/Gemfile.lock CHANGED
@@ -3,7 +3,7 @@ GEM
3
3
  specs:
4
4
  curb (0.7.9)
5
5
  diff-lcs (1.1.2)
6
- hpricot (0.8.3)
6
+ nokogiri (1.4.4)
7
7
  rspec (2.4.0)
8
8
  rspec-core (~> 2.4.0)
9
9
  rspec-expectations (~> 2.4.0)
@@ -18,5 +18,5 @@ PLATFORMS
18
18
 
19
19
  DEPENDENCIES
20
20
  curb
21
- hpricot
21
+ nokogiri
22
22
  rspec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.2
1
+ 2.2.0
data/crags.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{crags}
8
- s.version = "2.1.2"
8
+ s.version = "2.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Marney"]
12
- s.date = %q{2011-01-17}
12
+ s.date = %q{2011-02-08}
13
13
  s.description = %q{A library to help search across multiple craigslist locations.}
14
14
  s.email = %q{gotascii@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -33,7 +33,7 @@ Gem::Specification.new do |s|
33
33
  "lib/crags/search/country.rb",
34
34
  "lib/crags/search/location.rb",
35
35
  "lib/crags/search/search.rb",
36
- "lib/ext/hpricot/elem.rb",
36
+ "lib/ext/element.rb",
37
37
  "lib/ext/string.rb",
38
38
  "spec/crags/category_spec.rb",
39
39
  "spec/crags/country_spec.rb",
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
43
43
  "spec/crags/search/country_spec.rb",
44
44
  "spec/crags/search/location_spec.rb",
45
45
  "spec/crags/search/search_spec.rb",
46
- "spec/ext/hpricot/elem_spec.rb",
46
+ "spec/ext/element_spec.rb",
47
47
  "spec/ext/string_spec.rb",
48
48
  "spec/spec_helper.rb"
49
49
  ]
@@ -60,7 +60,7 @@ Gem::Specification.new do |s|
60
60
  "spec/crags/search/country_spec.rb",
61
61
  "spec/crags/search/location_spec.rb",
62
62
  "spec/crags/search/search_spec.rb",
63
- "spec/ext/hpricot/elem_spec.rb",
63
+ "spec/ext/element_spec.rb",
64
64
  "spec/ext/string_spec.rb",
65
65
  "spec/spec_helper.rb"
66
66
  ]
@@ -71,14 +71,14 @@ Gem::Specification.new do |s|
71
71
 
72
72
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
73
73
  s.add_runtime_dependency(%q<curb>, [">= 0"])
74
- s.add_runtime_dependency(%q<hpricot>, [">= 0"])
74
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
75
75
  else
76
76
  s.add_dependency(%q<curb>, [">= 0"])
77
- s.add_dependency(%q<hpricot>, [">= 0"])
77
+ s.add_dependency(%q<nokogiri>, [">= 0"])
78
78
  end
79
79
  else
80
80
  s.add_dependency(%q<curb>, [">= 0"])
81
- s.add_dependency(%q<hpricot>, [">= 0"])
81
+ s.add_dependency(%q<nokogiri>, [">= 0"])
82
82
  end
83
83
  end
84
84
 
data/lib/crags/fetcher.rb CHANGED
@@ -1,10 +1,10 @@
1
1
  module Crags
2
2
  module Fetcher
3
3
  def fetch_doc(url)
4
- Hpricot.parse(fetch_html(url))
4
+ Nokogiri::XML.parse(fetch_xml(url))
5
5
  end
6
6
 
7
- def fetch_html(url)
7
+ def fetch_xml(url)
8
8
  req = fetch_request(url)
9
9
  req.body_str
10
10
  end
data/lib/crags.rb CHANGED
@@ -1,9 +1,9 @@
1
- require 'hpricot'
1
+ require 'nokogiri'
2
2
  require 'curl'
3
3
  require 'erb'
4
4
  require 'ostruct'
5
5
  require 'ext/string'
6
- require 'ext/hpricot/elem'
6
+ require 'ext/element'
7
7
  require 'crags/fetcher'
8
8
  require 'crags/country'
9
9
  require 'crags/location'
@@ -0,0 +1,21 @@
1
+ module Element
2
+ def title
3
+ at("title").content
4
+ end
5
+
6
+ def url
7
+ self["about"].strip_http
8
+ end
9
+
10
+ def date_str
11
+ at("dc|date").content
12
+ end
13
+
14
+ def date
15
+ DateTime.parse(date_str)
16
+ end
17
+ end
18
+
19
+ class Nokogiri::XML::Element
20
+ include Element
21
+ end
@@ -5,17 +5,17 @@ describe Fetcher do
5
5
  extend Fetcher
6
6
  end
7
7
 
8
- it "hpricots the fetched html" do
9
- stub!(:fetch_html).with("url").and_return("html")
10
- Hpricot.should_receive(:parse).with("html").and_return("doc")
8
+ it "nokogiris the fetched xml" do
9
+ stub!(:fetch_xml).with("url").and_return("xml")
10
+ Nokogiri::XML.should_receive(:parse).with("xml").and_return("doc")
11
11
  fetch_doc("url").should == "doc"
12
12
  end
13
13
 
14
- it "fetch_requests a url" do
14
+ it "fetches a request when fetching xml" do
15
15
  curb = mock("curb")
16
16
  curb.stub!(:body_str).and_return("uhh")
17
17
  should_receive(:fetch_request).with("url").and_return(curb)
18
- fetch_html("url").should == "uhh"
18
+ fetch_xml("url").should == "uhh"
19
19
  end
20
20
 
21
21
  it "creates a new request" do
@@ -1,26 +1,30 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Hpricot::Elem do
3
+ class Tester
4
+ include Element
5
+ end
6
+
7
+ describe Nokogiri::XML::Element do
4
8
  before do
5
- @elem = Hpricot::Elem.new("<omg></omg>")
9
+ @elem = Tester.new
6
10
  end
7
11
 
8
12
  it "uses the inner_text of title element for title" do
9
13
  title = stub
10
- title.stub!(:inner_text).and_return("title!")
14
+ title.stub!(:content).and_return("title!")
11
15
  @elem.stub!(:at).with("title").and_return(title)
12
16
  @elem.title.should == "title!"
13
17
  end
14
18
 
15
19
  it "rdf:about attribute for the url" do
16
- @elem.stub!(:[]).with("rdf:about").and_return("url!")
20
+ @elem.stub!(:[]).with("about").and_return("url!")
17
21
  @elem.url.should == "url!"
18
22
  end
19
23
 
20
24
  it "uses the inner_text of the dc:date element for date_str" do
21
25
  dc_date = stub
22
- dc_date.stub!(:inner_text).and_return("date_str!")
23
- @elem.stub!(:at).with("dc:date").and_return(dc_date)
26
+ dc_date.stub!(:content).and_return("date_str!")
27
+ @elem.stub!(:at).with("dc|date").and_return(dc_date)
24
28
  @elem.date_str.should == "date_str!"
25
29
  end
26
30
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crags
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
- - 1
9
8
  - 2
10
- version: 2.1.2
9
+ - 0
10
+ version: 2.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin Marney
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-17 00:00:00 -05:00
18
+ date: 2011-02-08 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -35,7 +35,7 @@ dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  type: :runtime
37
37
  prerelease: false
38
- name: hpricot
38
+ name: nokogiri
39
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
@@ -72,7 +72,7 @@ files:
72
72
  - lib/crags/search/country.rb
73
73
  - lib/crags/search/location.rb
74
74
  - lib/crags/search/search.rb
75
- - lib/ext/hpricot/elem.rb
75
+ - lib/ext/element.rb
76
76
  - lib/ext/string.rb
77
77
  - spec/crags/category_spec.rb
78
78
  - spec/crags/country_spec.rb
@@ -82,7 +82,7 @@ files:
82
82
  - spec/crags/search/country_spec.rb
83
83
  - spec/crags/search/location_spec.rb
84
84
  - spec/crags/search/search_spec.rb
85
- - spec/ext/hpricot/elem_spec.rb
85
+ - spec/ext/element_spec.rb
86
86
  - spec/ext/string_spec.rb
87
87
  - spec/spec_helper.rb
88
88
  has_rdoc: true
@@ -128,6 +128,6 @@ test_files:
128
128
  - spec/crags/search/country_spec.rb
129
129
  - spec/crags/search/location_spec.rb
130
130
  - spec/crags/search/search_spec.rb
131
- - spec/ext/hpricot/elem_spec.rb
131
+ - spec/ext/element_spec.rb
132
132
  - spec/ext/string_spec.rb
133
133
  - spec/spec_helper.rb
@@ -1,19 +0,0 @@
1
- module Hpricot
2
- class Elem
3
- def title
4
- at("title").inner_text
5
- end
6
-
7
- def url
8
- self["rdf:about"].strip_http
9
- end
10
-
11
- def date_str
12
- at("dc:date").inner_text
13
- end
14
-
15
- def date
16
- DateTime.parse(date_str)
17
- end
18
- end
19
- end