jsl-placemaker 0.0.1.2 → 0.0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +47 -14
- data/lib/placemaker/{reader.rb → client.rb} +37 -14
- data/lib/placemaker/coordinates.rb +13 -0
- data/lib/placemaker/document.rb +23 -5
- data/lib/placemaker/extents.rb +23 -0
- data/lib/placemaker/location.rb +33 -0
- data/lib/placemaker/place_details.rb +28 -0
- data/lib/placemaker/xml_helper.rb +14 -0
- data/lib/placemaker/xml_parser.rb +16 -2
- data/lib/placemaker.rb +2 -0
- data/placemaker.gemspec +11 -8
- data/spec/placemaker/{reader_spec.rb → client_spec.rb} +7 -7
- data/spec/placemaker/coordinates_spec.rb +14 -0
- data/spec/placemaker/document_spec.rb +24 -4
- data/spec/placemaker/extents_spec.rb +56 -0
- data/spec/placemaker/{place_spec.rb → location_spec.rb} +9 -26
- data/spec/placemaker/place_details_spec.rb +28 -0
- data/spec/placemaker/xml_parser_spec.rb +18 -0
- metadata +17 -7
- data/lib/placemaker/place.rb +0 -47
data/README.rdoc
CHANGED
@@ -1,34 +1,67 @@
|
|
1
1
|
= Description
|
2
2
|
|
3
|
-
|
3
|
+
Yahoo! Placemaker is a freely available geoparsing Web service. It helps developers make their applications location-aware by
|
4
|
+
identifying places in unstructured and atomic content - feeds, web pages, news, status updates - and returning geographic metadata
|
5
|
+
for geographic indexing and markup.
|
6
|
+
|
7
|
+
This library is a Ruby interface for accessing the {Yahoo PlaceMaker API}[http://developer.yahoo.com/geo/placemaker/].
|
4
8
|
|
5
9
|
= Installation
|
6
10
|
|
7
|
-
Assuming that you've set up your ruby environment to pull gems from GitHub
|
11
|
+
Assuming that you've set up your ruby environment to pull gems from GitHub
|
12
|
+
(see {the GitHub instructions if you haven't yet done this}[http://gems.github.com]),
|
13
|
+
install placemaker with the following command:
|
8
14
|
|
9
15
|
sudo gem install jsl-placemaker
|
10
16
|
|
11
17
|
= Usage
|
12
18
|
|
13
|
-
The following is an example of using the Placemaker gem to read places in a standard feed.
|
19
|
+
The following is an example of using the Placemaker gem to read places in a standard feed. You'll have to get a Yahoo App ID first if you haven't
|
20
|
+
already done so.
|
14
21
|
|
15
22
|
require 'placemaker'
|
16
|
-
p = Placemaker.new(:appid => YOUR_APP_ID, :document_url => 'http://feeds.feedburner.com/wooster', :document_type => 'text/xml')
|
17
|
-
|
23
|
+
p = Placemaker::Client.new(:appid => YOUR_APP_ID, :document_url => 'http://feeds.feedburner.com/wooster', :document_type => 'text/xml')
|
24
|
+
p.fetch!
|
25
|
+
|
26
|
+
This will make a call to the Placemaker service and populate the Placemaker::Client object with data about the places in the content that you
|
27
|
+
sent to Yahoo. The information that you'll be interested in may be divided into "documents" and "meta-data".
|
28
|
+
|
29
|
+
== Documents
|
30
|
+
|
31
|
+
Once you've run the +fetch!+ method on the Placemaker::Client, you may invoke the method +documents+ which will return a set of Placemaker::Document
|
32
|
+
objects corresponding to each of the entries in the feed given to the placemaker service. For example, if you gave a +document_url+ pointing
|
33
|
+
to a feed containing 15 entries, there will be 15 documents in the resulting client object.
|
34
|
+
|
35
|
+
The following are methods that you may invoke on each of the Placemaker::Document objects to find out more about the place information that
|
36
|
+
Yahoo was able to glean from the input document:
|
37
|
+
|
38
|
+
* place_details - Returns a Placemaker::Location object that is a container for one named place mentioned in the document
|
39
|
+
* administrative_scope - Returns a Placemaker::Location object that is a container for the smallest administrative place that best describes the document
|
40
|
+
* geographic_scope - Returns a Placemaker::Location object that is a container for the smallest place that best describes the document
|
41
|
+
* extents - Returns a Placemaker::Extents object that is a container for the the map extents covering the places mentioned in the document
|
42
|
+
|
43
|
+
Below is a summary of the methods that these objects respond to. You may wish to browse the Placemaker rdoc files for these classes to see
|
44
|
+
for more details.
|
18
45
|
|
19
|
-
|
20
|
-
|
46
|
+
=== Placemaker::Location
|
47
|
+
|
48
|
+
Placemaker::Location objects contain a woe_id, name, location_type and centroid.
|
49
|
+
|
50
|
+
* woe_id - permanent identifier for the place
|
51
|
+
* name - fully qualified name for the place
|
52
|
+
* location_type - type name for the place
|
53
|
+
* centroid - centroid for the place, responds to +lat+ and +lng+
|
21
54
|
|
22
|
-
|
55
|
+
=== Placemaker::Extents
|
23
56
|
|
24
|
-
|
57
|
+
Placemaker::Extents are bounding boxes for an area of interest. They respond to methods for +center+, +south_west+ and +north_east+. In
|
58
|
+
all of these cases, they return a Placemaker::Coordinates object responding to +lat+ and +lng+.
|
25
59
|
|
26
|
-
|
60
|
+
== Meta-data
|
27
61
|
|
28
|
-
|
29
|
-
|
30
|
-
and surely has bugs.
|
62
|
+
The request to the Yahoo place coding service returns information about the request. You may invoke the methods +processing_time+,
|
63
|
+
+version+, and +document_length+ to find out more about the request.
|
31
64
|
|
32
65
|
= Author
|
33
66
|
|
34
|
-
Justin S. Leitgeb,
|
67
|
+
Justin S. Leitgeb, justin@phq.org
|
@@ -1,34 +1,57 @@
|
|
1
1
|
module Placemaker
|
2
|
-
|
2
|
+
|
3
|
+
# Main interface to the Placemaker API.
|
4
|
+
class Client
|
3
5
|
POST_FIELDS = %w[ appid document_content document_url document_type document_title
|
4
6
|
auto_disambiguate focus_woe_id input_language output_type ].map{|f| f.to_sym}
|
5
7
|
|
6
|
-
attr_reader :documents
|
7
|
-
|
8
8
|
def initialize(options = {})
|
9
9
|
@options = options
|
10
10
|
@options[:appid] ||= ENV['PLACEMAKER_APPID']
|
11
|
-
|
11
|
+
|
12
|
+
@xml_parser = Placemaker::XmlParser.new('NODOC')
|
13
|
+
|
12
14
|
verify_content_set
|
13
15
|
verify_document_type_set
|
14
16
|
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
@options[f] # @options[:appid]
|
19
|
-
end # end
|
20
|
-
end
|
21
|
-
|
22
|
-
def fetch
|
18
|
+
# Fetches the place information for input parameters from the Yahoo Placemaker service
|
19
|
+
def fetch!
|
23
20
|
fields = POST_FIELDS.reject{|f| @options[f].nil? }.map do |f|
|
24
21
|
# Change ruby-form fields to url type, e.g., document_content => documentContent
|
25
22
|
cgi_param = f.to_s.gsub(/\_(.)/) {|s| s.upcase}.gsub('_', '').sub(/url/i, 'URL')
|
26
23
|
Curl::PostField.content(cgi_param, @options[f])
|
27
24
|
end
|
28
25
|
|
29
|
-
res
|
30
|
-
xml_parser = Placemaker::XmlParser.new(res.body_str)
|
31
|
-
|
26
|
+
res = Curl::Easy.http_post('http://wherein.yahooapis.com/v1/document', *fields)
|
27
|
+
@xml_parser = Placemaker::XmlParser.new(res.body_str)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a collection of Placemaker::Document items as containers for content location information
|
31
|
+
def documents
|
32
|
+
@xml_parser.documents
|
33
|
+
end
|
34
|
+
|
35
|
+
# time in seconds to process the document
|
36
|
+
def processing_time
|
37
|
+
@xml_parser.processing_time
|
38
|
+
end
|
39
|
+
|
40
|
+
# version of the software used to process the document
|
41
|
+
def version
|
42
|
+
@xml_parser.version
|
43
|
+
end
|
44
|
+
|
45
|
+
# length in bytes of the document
|
46
|
+
def document_length
|
47
|
+
@xml_parser.document_length
|
48
|
+
end
|
49
|
+
|
50
|
+
# Create convenience methods to access post fields from the @options hash, mostly for testing.
|
51
|
+
POST_FIELDS.each do |f|
|
52
|
+
define_method(f) do # def appid
|
53
|
+
@options[f] # @options[:appid]
|
54
|
+
end # end
|
32
55
|
end
|
33
56
|
|
34
57
|
private
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Placemaker
|
2
|
+
class Coordinates
|
3
|
+
include Placemaker::XmlHelper
|
4
|
+
|
5
|
+
def lat
|
6
|
+
@nodeset.search('.//xmlns:latitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f
|
7
|
+
end
|
8
|
+
|
9
|
+
def lng
|
10
|
+
@nodeset.search('.//xmlns:longitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/placemaker/document.rb
CHANGED
@@ -1,14 +1,32 @@
|
|
1
1
|
module Placemaker
|
2
|
+
|
2
3
|
class Document
|
3
|
-
|
4
|
-
@nodeset = nodeset
|
5
|
-
end
|
4
|
+
include Placemaker::XmlHelper
|
6
5
|
|
7
|
-
|
6
|
+
# Returns a Placemaker::Location object that is a container for one named place mentioned in the document
|
7
|
+
def place_details
|
8
8
|
@nodeset.search('.//xmlns:placeDetails', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').map do |p|
|
9
|
-
Placemaker::
|
9
|
+
Placemaker::PlaceDetails.new(p)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
# Returns a Placemaker::Location object that is a container for the smallest administrative place that best describes the document
|
14
|
+
def administrative_scope
|
15
|
+
as = @nodeset.search('.//xmlns:administrativeScope', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').first
|
16
|
+
Placemaker::Location.new(as) unless as.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a Placemaker::Location object that is a container for the smallest place that best describes the document
|
20
|
+
def geographic_scope
|
21
|
+
gs = @nodeset.search('.//xmlns:geographicScope', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').first
|
22
|
+
Placemaker::Location.new(gs) unless gs.nil?
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns a Placemaker::Extents object that is a container for the the map extents covering the places mentioned in the document
|
26
|
+
def extents
|
27
|
+
extents = @nodeset.search('.//xmlns:extents', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').first
|
28
|
+
Placemaker::Extents.new(extents) unless extents.nil?
|
29
|
+
end
|
13
30
|
end
|
31
|
+
|
14
32
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Placemaker
|
2
|
+
|
3
|
+
# container for the the map extents covering the places mentioned in the document
|
4
|
+
class Extents
|
5
|
+
include Placemaker::XmlHelper
|
6
|
+
|
7
|
+
# coordinates of center (WGS84)
|
8
|
+
def center
|
9
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:center', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema'))
|
10
|
+
end
|
11
|
+
|
12
|
+
# coordinates of southwest corner of bounding box (WGS84)
|
13
|
+
def south_west
|
14
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:southWest', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema'))
|
15
|
+
end
|
16
|
+
|
17
|
+
# coordinates of northeast corner of bounding box (WGS84)
|
18
|
+
def north_east
|
19
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:northEast', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema'))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Placemaker
|
2
|
+
|
3
|
+
# Parses and contains data for +place+, +administrative scope+ and +geographic scope+ elements.
|
4
|
+
class Location
|
5
|
+
include Placemaker::XmlHelper
|
6
|
+
|
7
|
+
# permanent identifier for the place
|
8
|
+
def woe_id
|
9
|
+
nested_node('woeId').to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
# fully qualified name for the place
|
13
|
+
def name
|
14
|
+
nested_node('name')
|
15
|
+
end
|
16
|
+
|
17
|
+
# place type name for the place
|
18
|
+
def location_type
|
19
|
+
nested_node('type')
|
20
|
+
end
|
21
|
+
|
22
|
+
# centroid for the place
|
23
|
+
def centroid
|
24
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:centroid', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema'))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def nested_node(name)
|
30
|
+
@nodeset.search(".//xmlns:#{name}", 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Placemaker
|
2
|
+
|
3
|
+
# container for one named place mentioned in the document
|
4
|
+
class PlaceDetails
|
5
|
+
include Placemaker::XmlHelper
|
6
|
+
|
7
|
+
# Returns a Placemaker::Location object as a container for place information.
|
8
|
+
def place
|
9
|
+
Placemaker::Location.new(@nodeset.search('.//xmlns:place', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema'))
|
10
|
+
end
|
11
|
+
|
12
|
+
# type of match (0=text or text and coordinates, 1=coordinates only)
|
13
|
+
def match_type
|
14
|
+
nested_node('matchType').to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
# relative weight of the place within the document (range 1-100)
|
18
|
+
def weight
|
19
|
+
nested_node('weight').to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
# confidence that the document mentions the place (range 1-10)
|
23
|
+
def confidence
|
24
|
+
nested_node('confidence').to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Placemaker
|
2
|
+
module XmlHelper
|
3
|
+
def initialize(nodeset)
|
4
|
+
@nodeset = nodeset
|
5
|
+
end
|
6
|
+
|
7
|
+
# Returns the inner text of a node with the given name under the current @nodeset
|
8
|
+
def nested_node(name)
|
9
|
+
@nodeset.search(".//xmlns:#{name}", 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text
|
10
|
+
end
|
11
|
+
|
12
|
+
private :nested_node
|
13
|
+
end
|
14
|
+
end
|
@@ -3,10 +3,24 @@ module Placemaker
|
|
3
3
|
def initialize(xml_body)
|
4
4
|
@body = xml_body
|
5
5
|
@xml = Nokogiri::XML(xml_body)
|
6
|
+
end
|
7
|
+
|
8
|
+
# time in seconds to process the document
|
9
|
+
def processing_time
|
10
|
+
@xml.xpath('.//xmlns:processingTime', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f
|
11
|
+
end
|
12
|
+
|
13
|
+
# version of the software used to process the document
|
14
|
+
def version
|
15
|
+
@xml.xpath('.//xmlns:version', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.strip
|
16
|
+
end
|
17
|
+
|
18
|
+
# length in bytes of the document
|
19
|
+
def document_length
|
20
|
+
@xml.xpath('.//xmlns:documentLength', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_i
|
6
21
|
end
|
7
22
|
|
8
|
-
#
|
9
|
-
# Returns a collection of Placemaker::Document objects.
|
23
|
+
# Returns a set of Placemaker::Document objects as containers for content location information
|
10
24
|
def documents
|
11
25
|
@xml.xpath('//xmlns:document', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').map do |d|
|
12
26
|
Placemaker::Document.new(d)
|
data/lib/placemaker.rb
CHANGED
data/placemaker.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{placemaker}
|
5
|
-
s.version = "0.0.1.
|
5
|
+
s.version = "0.0.1.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Justin Leitgeb"]
|
@@ -14,11 +14,12 @@ Gem::Specification.new do |s|
|
|
14
14
|
]
|
15
15
|
|
16
16
|
|
17
|
-
s.files = ["lib/core_ext/array.rb", "lib/core_ext/hash.rb", "lib/placemaker/
|
18
|
-
"lib/placemaker/
|
19
|
-
"placemaker.
|
20
|
-
"spec/
|
21
|
-
"spec/placemaker/
|
17
|
+
s.files = ["lib/core_ext/array.rb", "lib/core_ext/hash.rb", "lib/placemaker/client.rb", "lib/placemaker/coordinates.rb",
|
18
|
+
"lib/placemaker/document.rb", "lib/placemaker/extents.rb", "lib/placemaker/location.rb", "lib/placemaker/place_details.rb",
|
19
|
+
"lib/placemaker/xml_helper.rb", "lib/placemaker/xml_parser.rb", "lib/placemaker.rb", "LICENSE", "placemaker.gemspec",
|
20
|
+
"Rakefile", "README.rdoc", "spec/fixtures/xml_rss_feed_result.xml", "spec/placemaker/client_spec.rb", "spec/placemaker/coordinates_spec.rb",
|
21
|
+
"spec/placemaker/document_spec.rb", "spec/placemaker/extents_spec.rb", "spec/placemaker/location_spec.rb",
|
22
|
+
"spec/placemaker/place_details_spec.rb", "spec/placemaker/xml_parser_spec.rb", "spec/spec_helper.rb"]
|
22
23
|
|
23
24
|
s.has_rdoc = true
|
24
25
|
s.homepage = %q{http://github.com/jsl/placemaker}
|
@@ -26,8 +27,10 @@ Gem::Specification.new do |s|
|
|
26
27
|
s.require_paths = ["lib"]
|
27
28
|
s.rubygems_version = %q{1.3.1}
|
28
29
|
s.summary = %q{Ruby interface over the Yahoo Placemaker API}
|
29
|
-
|
30
|
-
|
30
|
+
|
31
|
+
s.test_files = ["spec/fixtures/xml_rss_feed_result.xml", "spec/placemaker/client_spec.rb", "spec/placemaker/coordinates_spec.rb",
|
32
|
+
"spec/placemaker/document_spec.rb", "spec/placemaker/extents_spec.rb", "spec/placemaker/location_spec.rb",
|
33
|
+
"spec/placemaker/place_details_spec.rb", "spec/placemaker/xml_parser_spec.rb", "spec/spec_helper.rb"]
|
31
34
|
|
32
35
|
s.extra_rdoc_files = [ "README.rdoc" ]
|
33
36
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
2
|
|
3
|
-
describe Placemaker::
|
3
|
+
describe Placemaker::Client do
|
4
4
|
before do
|
5
5
|
@valid_opts = {
|
6
6
|
:document_url => 'http://www.example.com',
|
@@ -11,36 +11,36 @@ describe Placemaker::Reader do
|
|
11
11
|
describe "object initialization" do
|
12
12
|
it "should set appid to the value of ENV['PLACEMAKER_APPID']" do
|
13
13
|
ENV['PLACEMAKER_APPID'] = 'foo'
|
14
|
-
p = Placemaker::
|
14
|
+
p = Placemaker::Client.new(@valid_opts)
|
15
15
|
p.appid.should == 'foo'
|
16
16
|
end
|
17
17
|
|
18
18
|
it "should initialize #documents to an empty array" do
|
19
|
-
p = Placemaker::
|
19
|
+
p = Placemaker::Client.new(@valid_opts)
|
20
20
|
p.documents.should be_a(Array)
|
21
21
|
p.documents.should be_empty
|
22
22
|
end
|
23
23
|
|
24
24
|
it "should raise an argument error if the document_type is not correctly set" do
|
25
25
|
lambda {
|
26
|
-
Placemaker::
|
26
|
+
Placemaker::Client.new(@valid_opts.except(:document_type))
|
27
27
|
}.should raise_error(ArgumentError)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "should set the appid to the value of options[:appid] if provided" do
|
31
31
|
ENV['PLACEMAKER_APPID'] = 'foo'
|
32
|
-
p = Placemaker::
|
32
|
+
p = Placemaker::Client.new(@valid_opts.merge(:appid => 'fark', :document_url => 'foo'))
|
33
33
|
p.appid.should == 'fark'
|
34
34
|
end
|
35
35
|
|
36
36
|
it "should create methods to allow access to configuration parameters" do
|
37
|
-
p = Placemaker::
|
37
|
+
p = Placemaker::Client.new(@valid_opts.merge(:document_content => 'foo'))
|
38
38
|
p.document_content.should == 'foo'
|
39
39
|
end
|
40
40
|
|
41
41
|
it "should raise an error if both document_content and document_url are nil" do
|
42
42
|
lambda {
|
43
|
-
p = Placemaker::
|
43
|
+
p = Placemaker::Client.new
|
44
44
|
}.should raise_error(ArgumentError)
|
45
45
|
end
|
46
46
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
|
+
|
3
|
+
describe Placemaker::Coordinates 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
|
+
@coords = @doc.place_details.first.place.centroid
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be a Placemaker::Coordinates object" do
|
12
|
+
@coords.should be_a(Placemaker::Coordinates)
|
13
|
+
end
|
14
|
+
end
|
@@ -6,14 +6,34 @@ describe Placemaker::Document do
|
|
6
6
|
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
7
|
@doc = @xmlp.documents[5]
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
describe "#places" do
|
11
11
|
it "should have 4 places for the given node" do
|
12
|
-
@doc.
|
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
|
13
33
|
end
|
14
34
|
|
15
|
-
it "should return a Placemaker::
|
16
|
-
@doc.
|
35
|
+
it "should return a Placemaker::Location object" do
|
36
|
+
@doc.geographic_scope.should be_a(Placemaker::Location)
|
17
37
|
end
|
18
38
|
end
|
19
39
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '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
|
@@ -1,61 +1,44 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
|
2
2
|
|
3
|
-
describe Placemaker::
|
3
|
+
describe Placemaker::Location do
|
4
4
|
before do
|
5
5
|
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
6
|
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
|
-
@doc = @xmlp.documents[5]
|
8
|
-
@
|
7
|
+
@doc = @xmlp.documents[5]
|
8
|
+
@loc = @doc.place_details.first.place
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#woe_id" do
|
12
12
|
it "should equal 2442047" do
|
13
|
-
@
|
13
|
+
@loc.woe_id.should == 2442047
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "place_type" do
|
18
18
|
it "should be Town" do
|
19
|
-
@
|
19
|
+
@loc.location_type.should == 'Town'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#name" do
|
24
24
|
it "should be Los Angeles, CA, US" do
|
25
|
-
@
|
25
|
+
@loc.name.should == 'Los Angeles, CA, US'
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "centroid" do
|
30
30
|
|
31
31
|
it "should be a Placemaker::Point object" do
|
32
|
-
@
|
32
|
+
@loc.centroid.should be_a(Placemaker::Coordinates)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should return an object with lat set to 34.0533" do
|
36
|
-
@
|
36
|
+
@loc.centroid.lat.should == 34.0533
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should return an object with lng set to -118.245" do
|
40
|
-
@
|
40
|
+
@loc.centroid.lng.should == -118.245
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
describe "#match_type" do
|
45
|
-
it "should be 0" do
|
46
|
-
@place.match_type.should == 0
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "#weight" do
|
51
|
-
it "should be 1" do
|
52
|
-
@place.weight.should == 1
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe "#confidence" do
|
57
|
-
it "should be 9" do
|
58
|
-
@place.confidence.should == 9
|
59
|
-
end
|
60
|
-
end
|
61
44
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', '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
|
@@ -5,6 +5,24 @@ describe Placemaker::XmlParser do
|
|
5
5
|
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml]))
|
6
6
|
@xmlp = Placemaker::XmlParser.new(@xml_str)
|
7
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
|
8
26
|
|
9
27
|
describe "#documents" do
|
10
28
|
it "should return 15 documents" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsl-placemaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Leitgeb
|
@@ -43,9 +43,13 @@ extra_rdoc_files:
|
|
43
43
|
files:
|
44
44
|
- lib/core_ext/array.rb
|
45
45
|
- lib/core_ext/hash.rb
|
46
|
+
- lib/placemaker/client.rb
|
47
|
+
- lib/placemaker/coordinates.rb
|
46
48
|
- lib/placemaker/document.rb
|
47
|
-
- lib/placemaker/
|
48
|
-
- lib/placemaker/
|
49
|
+
- lib/placemaker/extents.rb
|
50
|
+
- lib/placemaker/location.rb
|
51
|
+
- lib/placemaker/place_details.rb
|
52
|
+
- lib/placemaker/xml_helper.rb
|
49
53
|
- lib/placemaker/xml_parser.rb
|
50
54
|
- lib/placemaker.rb
|
51
55
|
- LICENSE
|
@@ -53,9 +57,12 @@ files:
|
|
53
57
|
- Rakefile
|
54
58
|
- README.rdoc
|
55
59
|
- spec/fixtures/xml_rss_feed_result.xml
|
60
|
+
- spec/placemaker/client_spec.rb
|
61
|
+
- spec/placemaker/coordinates_spec.rb
|
56
62
|
- spec/placemaker/document_spec.rb
|
57
|
-
- spec/placemaker/
|
58
|
-
- spec/placemaker/
|
63
|
+
- spec/placemaker/extents_spec.rb
|
64
|
+
- spec/placemaker/location_spec.rb
|
65
|
+
- spec/placemaker/place_details_spec.rb
|
59
66
|
- spec/placemaker/xml_parser_spec.rb
|
60
67
|
- spec/spec_helper.rb
|
61
68
|
has_rdoc: true
|
@@ -92,8 +99,11 @@ specification_version: 2
|
|
92
99
|
summary: Ruby interface over the Yahoo Placemaker API
|
93
100
|
test_files:
|
94
101
|
- spec/fixtures/xml_rss_feed_result.xml
|
102
|
+
- spec/placemaker/client_spec.rb
|
103
|
+
- spec/placemaker/coordinates_spec.rb
|
95
104
|
- spec/placemaker/document_spec.rb
|
96
|
-
- spec/placemaker/
|
97
|
-
- spec/placemaker/
|
105
|
+
- spec/placemaker/extents_spec.rb
|
106
|
+
- spec/placemaker/location_spec.rb
|
107
|
+
- spec/placemaker/place_details_spec.rb
|
98
108
|
- spec/placemaker/xml_parser_spec.rb
|
99
109
|
- spec/spec_helper.rb
|
data/lib/placemaker/place.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
module Placemaker
|
2
|
-
class Point < OpenStruct
|
3
|
-
end
|
4
|
-
|
5
|
-
class Place
|
6
|
-
def initialize(nodeset)
|
7
|
-
@nodeset = nodeset
|
8
|
-
end
|
9
|
-
|
10
|
-
def centroid
|
11
|
-
centroid = @nodeset.search('.//xmlns:centroid', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema')
|
12
|
-
lat = centroid.search('.//xmlns:latitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f
|
13
|
-
lng = centroid.search('.//xmlns:longitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f
|
14
|
-
Placemaker::Point.new(:lat => lat, :lng => lng)
|
15
|
-
end
|
16
|
-
|
17
|
-
def place_type
|
18
|
-
nested_node('type')
|
19
|
-
end
|
20
|
-
|
21
|
-
def match_type
|
22
|
-
nested_node('matchType').to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
def weight
|
26
|
-
nested_node('weight').to_i
|
27
|
-
end
|
28
|
-
|
29
|
-
def confidence
|
30
|
-
nested_node('confidence').to_i
|
31
|
-
end
|
32
|
-
|
33
|
-
def name
|
34
|
-
nested_node('name')
|
35
|
-
end
|
36
|
-
|
37
|
-
def woe_id
|
38
|
-
nested_node('woeId').to_i
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def nested_node(name)
|
44
|
-
@nodeset.search(".//xmlns:#{name}", 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|