placemaker 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +14 -0
- data/LICENSE +20 -0
- data/README.rdoc +76 -0
- data/Rakefile +28 -0
- data/lib/placemaker/client.rb +75 -0
- data/lib/placemaker/coordinates.rb +13 -0
- data/lib/placemaker/document.rb +44 -0
- data/lib/placemaker/extents.rb +25 -0
- data/lib/placemaker/location.rb +35 -0
- data/lib/placemaker/place_details.rb +28 -0
- data/lib/placemaker/reference.rb +34 -0
- data/lib/placemaker/xml_helper.rb +14 -0
- data/lib/placemaker/xml_parser.rb +33 -0
- data/lib/placemaker.rb +9 -0
- data/spec/fixtures/xml_rss_feed_result.xml +636 -0
- data/spec/placemaker/client_spec.rb +48 -0
- data/spec/placemaker/coordinates_spec.rb +14 -0
- data/spec/placemaker/document_spec.rb +51 -0
- data/spec/placemaker/extents_spec.rb +56 -0
- data/spec/placemaker/location_spec.rb +44 -0
- data/spec/placemaker/place_details_spec.rb +28 -0
- data/spec/placemaker/reference_spec.rb +40 -0
- data/spec/placemaker/xml_parser_spec.rb +36 -0
- data/spec/spec_helper.rb +14 -0
- metadata +130 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Placemaker::Document do
|
4
|
+
before do
|
5
|
+
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
|
+
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
|
+
@doc = @xmlp.documents[5]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#places" do
|
11
|
+
it "should have 4 places for the given node" do
|
12
|
+
@doc.place_details.size.should == 4
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return a Placemaker::PlaceDetails object for the first node" do
|
16
|
+
@doc.place_details.first.should be_a(Placemaker::PlaceDetails)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#administrative_scope" do
|
21
|
+
it "should have an administrative scope" do
|
22
|
+
@doc.administrative_scope.should_not be_nil
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return a Placemaker::Location object" do
|
26
|
+
@doc.administrative_scope.should be_a(Placemaker::Location)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#geographic_scope" do
|
31
|
+
it "should have an geographic scope" do
|
32
|
+
@doc.geographic_scope.should_not be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return a Placemaker::Location object" do
|
36
|
+
@doc.geographic_scope.should be_a(Placemaker::Location)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#reference_list" do
|
41
|
+
it "should return an array" do
|
42
|
+
@doc.reference_list.size.should == 5
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should contain Reference objects" do
|
46
|
+
@doc.reference_list.each do |rl|
|
47
|
+
rl.should be_a(Placemaker::Reference)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Placemaker::Extents do
|
4
|
+
before do
|
5
|
+
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
|
+
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
|
+
@doc = @xmlp.documents[5]
|
8
|
+
@extents = @doc.extents
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be a Placemaker::Extents object" do
|
12
|
+
@extents.should be_a(Placemaker::Extents)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#center" do
|
16
|
+
it "should return a Placemaker::Point object" do
|
17
|
+
@extents.center.should be_a(Placemaker::Coordinates)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have a lat of 38.8913" do
|
21
|
+
@extents.center.lat.should == 38.8913
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should have a lng of -77.0337" do
|
25
|
+
@extents.center.lng.should == -77.0337
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#south_west" do
|
30
|
+
it "should return a Placemaker::Point object" do
|
31
|
+
@extents.south_west.should be_a(Placemaker::Coordinates)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should have a lat of 18.9108" do
|
35
|
+
@extents.south_west.lat.should == 18.9108
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have a lng of -167.276" do
|
39
|
+
@extents.south_west.lng.should == -167.276
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#north_east" do
|
44
|
+
it "should return a Placemaker::Point object" do
|
45
|
+
@extents.north_east.should be_a(Placemaker::Coordinates)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should have a lat of 72.8961" do
|
49
|
+
@extents.north_east.lat.should == 72.8961
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have a lng of -66.6879" do
|
53
|
+
@extents.north_east.lng.should == -66.6879
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Placemaker::Location do
|
4
|
+
before do
|
5
|
+
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
|
+
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
|
+
@doc = @xmlp.documents[5]
|
8
|
+
@loc = @doc.place_details.first.place
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#woe_id" do
|
12
|
+
it "should equal 2442047" do
|
13
|
+
@loc.woe_id.should == 2442047
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "place_type" do
|
18
|
+
it "should be Town" do
|
19
|
+
@loc.location_type.should == 'Town'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#name" do
|
24
|
+
it "should be Los Angeles, CA, US" do
|
25
|
+
@loc.name.should == 'Los Angeles, CA, US'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "centroid" do
|
30
|
+
|
31
|
+
it "should be a Placemaker::Point object" do
|
32
|
+
@loc.centroid.should be_a(Placemaker::Coordinates)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return an object with lat set to 34.0533" do
|
36
|
+
@loc.centroid.lat.should == 34.0533
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should return an object with lng set to -118.245" do
|
40
|
+
@loc.centroid.lng.should == -118.245
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Placemaker::PlaceDetails do
|
4
|
+
before do
|
5
|
+
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
|
+
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
|
+
@doc = @xmlp.documents[5]
|
8
|
+
@pd = @doc.place_details.first
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#match_type" do
|
12
|
+
it "should be 0" do
|
13
|
+
@pd.match_type.should == 0
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#weight" do
|
18
|
+
it "should be 1" do
|
19
|
+
@pd.weight.should == 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#confidence" do
|
24
|
+
it "should be 9" do
|
25
|
+
@pd.confidence.should == 9
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Placemaker::Reference do
|
4
|
+
before do
|
5
|
+
xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
|
+
xmlp = Placemaker::XmlParser.new(xml_str)
|
7
|
+
doc = xmlp.documents[5]
|
8
|
+
@reference = doc.reference_list.first
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#woeIds" do
|
12
|
+
it "should be X" do
|
13
|
+
@reference.woe_ids.should == '23424977'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#start" do
|
18
|
+
it "should be X" do
|
19
|
+
@reference.start.should == '1997'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#end" do
|
24
|
+
it "should be X" do
|
25
|
+
@reference.end.should == '2004'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#text" do
|
30
|
+
it "should be Y" do
|
31
|
+
@reference.text.should == 'America'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#xpath" do
|
36
|
+
it "should be X" do
|
37
|
+
@reference.xpath.should == '/rss[1]/channel[1]/item[6]/description[1]'
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Placemaker::XmlParser do
|
4
|
+
before do
|
5
|
+
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
|
+
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "processing_time" do
|
10
|
+
it "should return 0.028125" do
|
11
|
+
@xmlp.processing_time.should == 0.028125
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "version" do
|
16
|
+
it "should return build 090508" do
|
17
|
+
@xmlp.version.should == 'build 090508'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "document_length" do
|
22
|
+
it "should return 29700" do
|
23
|
+
@xmlp.document_length.should == 29700
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#documents" do
|
28
|
+
it "should return 15 documents" do
|
29
|
+
@xmlp.documents.size.should == 15
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should contain all Placemaker::Document objects" do
|
33
|
+
@xmlp.documents.all?{|d| d.class == Placemaker::Document}.should be_true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
require 'placemaker'
|
5
|
+
|
6
|
+
shared_examples_for "all backends" do
|
7
|
+
it "should respond to #get" do
|
8
|
+
@backend.should respond_to(:get)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should respond to #set" do
|
12
|
+
@backend.should respond_to(:set)
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: placemaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Justin Leitgeb
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-01-15 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: curb
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: nokogiri
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
49
|
+
description: " placemaker is a Ruby client for the Yahoo Placemaker API. It uses\n the nokogiri and curb gems to help the user to efficiently query the\n Placemaker service and parse the XML response. \n"
|
50
|
+
email: justin@stackbuilders.com
|
51
|
+
executables: []
|
52
|
+
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files:
|
56
|
+
- README.rdoc
|
57
|
+
files:
|
58
|
+
- lib/placemaker/client.rb
|
59
|
+
- lib/placemaker/coordinates.rb
|
60
|
+
- lib/placemaker/document.rb
|
61
|
+
- lib/placemaker/extents.rb
|
62
|
+
- lib/placemaker/location.rb
|
63
|
+
- lib/placemaker/place_details.rb
|
64
|
+
- lib/placemaker/reference.rb
|
65
|
+
- lib/placemaker/xml_helper.rb
|
66
|
+
- lib/placemaker/xml_parser.rb
|
67
|
+
- lib/placemaker.rb
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE
|
71
|
+
- Rakefile
|
72
|
+
- README.rdoc
|
73
|
+
- spec/fixtures/xml_rss_feed_result.xml
|
74
|
+
- spec/placemaker/client_spec.rb
|
75
|
+
- spec/placemaker/coordinates_spec.rb
|
76
|
+
- spec/placemaker/document_spec.rb
|
77
|
+
- spec/placemaker/extents_spec.rb
|
78
|
+
- spec/placemaker/location_spec.rb
|
79
|
+
- spec/placemaker/place_details_spec.rb
|
80
|
+
- spec/placemaker/reference_spec.rb
|
81
|
+
- spec/placemaker/xml_parser_spec.rb
|
82
|
+
- spec/spec_helper.rb
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: http://github.com/jsl/placemaker
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options:
|
89
|
+
- --title
|
90
|
+
- Placemaker
|
91
|
+
- --main
|
92
|
+
- README.rdoc
|
93
|
+
- --line-numbers
|
94
|
+
- --inline-source
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
hash: 3
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.4.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Ruby interface over the Yahoo Placemaker API
|
122
|
+
test_files:
|
123
|
+
- spec/placemaker/client_spec.rb
|
124
|
+
- spec/placemaker/coordinates_spec.rb
|
125
|
+
- spec/placemaker/document_spec.rb
|
126
|
+
- spec/placemaker/extents_spec.rb
|
127
|
+
- spec/placemaker/location_spec.rb
|
128
|
+
- spec/placemaker/place_details_spec.rb
|
129
|
+
- spec/placemaker/reference_spec.rb
|
130
|
+
- spec/placemaker/xml_parser_spec.rb
|