placemaker 0.0.2 → 0.0.3
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/README.rdoc +4 -2
- data/lib/placemaker/client.rb +2 -2
- data/lib/placemaker/coordinates.rb +2 -2
- data/lib/placemaker/document.rb +5 -5
- data/lib/placemaker/extents.rb +3 -3
- data/lib/placemaker/location.rb +2 -2
- data/lib/placemaker/place_details.rb +1 -1
- data/lib/placemaker/xml_helper.rb +1 -1
- data/lib/placemaker/xml_parser.rb +3 -4
- data/spec/placemaker/coordinates_spec.rb +3 -4
- data/spec/placemaker/document_spec.rb +2 -3
- data/spec/placemaker/extents_spec.rb +3 -4
- data/spec/placemaker/location_spec.rb +3 -4
- data/spec/placemaker/place_details_spec.rb +3 -4
- data/spec/placemaker/reference_spec.rb +1 -2
- data/spec/placemaker/xml_parser_spec.rb +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -20,7 +20,7 @@ The following is an example of using the Placemaker gem to read places in a stan
|
|
20
20
|
already done so.
|
21
21
|
|
22
22
|
require 'placemaker'
|
23
|
-
p = Placemaker::Client.new(:appid => YOUR_APP_ID, :document_url => 'http://feeds.
|
23
|
+
p = Placemaker::Client.new(:appid => YOUR_APP_ID, :document_url => 'http://feeds.nytimes.com/nyt/rss/HomePage', :document_type => 'text/xml')
|
24
24
|
p.fetch!
|
25
25
|
|
26
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
|
@@ -73,4 +73,6 @@ The request to the Yahoo place coding service returns information about the requ
|
|
73
73
|
|
74
74
|
= Author
|
75
75
|
|
76
|
-
Justin S. Leitgeb, justin@
|
76
|
+
Justin S. Leitgeb, justin@stackbuilders.com
|
77
|
+
|
78
|
+
Copyright (c) 2011 {Stack Builders Inc.}[http://stackbuilders.com]
|
data/lib/placemaker/client.rb
CHANGED
@@ -4,8 +4,8 @@ module Placemaker
|
|
4
4
|
|
5
5
|
# Main interface to the Placemaker API.
|
6
6
|
class Client
|
7
|
-
POST_FIELDS = %w[
|
8
|
-
|
7
|
+
POST_FIELDS = %w[ appid document_content document_url document_type document_title
|
8
|
+
auto_disambiguate focus_woe_id input_language output_type ].map(&:to_sym)
|
9
9
|
|
10
10
|
def initialize(options = {})
|
11
11
|
@options = options
|
@@ -3,11 +3,11 @@ module Placemaker
|
|
3
3
|
include Placemaker::XmlHelper
|
4
4
|
|
5
5
|
def lat
|
6
|
-
|
6
|
+
nested_node('latitude').to_f
|
7
7
|
end
|
8
8
|
|
9
9
|
def lng
|
10
|
-
|
10
|
+
nested_node('longitude').to_f
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/placemaker/document.rb
CHANGED
@@ -11,31 +11,31 @@ module Placemaker
|
|
11
11
|
|
12
12
|
# Returns a Placemaker::Location object that is a container for one named place mentioned in the document
|
13
13
|
def place_details
|
14
|
-
@nodeset.search('.//xmlns:placeDetails'
|
14
|
+
@nodeset.search('.//xmlns:placeDetails').map do |p|
|
15
15
|
Placemaker::PlaceDetails.new(p)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
# Returns a Placemaker::Location object that is a container for the smallest administrative place that best describes the document
|
20
20
|
def administrative_scope
|
21
|
-
as = @nodeset.search('.//xmlns:administrativeScope'
|
21
|
+
as = @nodeset.search('.//xmlns:administrativeScope').first
|
22
22
|
Placemaker::Location.new(as) unless as.nil?
|
23
23
|
end
|
24
24
|
|
25
25
|
# Returns a Placemaker::Location object that is a container for the smallest place that best describes the document
|
26
26
|
def geographic_scope
|
27
|
-
gs = @nodeset.search('.//xmlns:geographicScope'
|
27
|
+
gs = @nodeset.search('.//xmlns:geographicScope').first
|
28
28
|
Placemaker::Location.new(gs) unless gs.nil?
|
29
29
|
end
|
30
30
|
|
31
31
|
# Returns a Placemaker::Extents object that is a container for the the map extents covering the places mentioned in the document
|
32
32
|
def extents
|
33
|
-
extents = @nodeset.search('.//xmlns:extents'
|
33
|
+
extents = @nodeset.search('.//xmlns:extents').first
|
34
34
|
Placemaker::Extents.new(extents) unless extents.nil?
|
35
35
|
end
|
36
36
|
|
37
37
|
def reference_list
|
38
|
-
@nodeset.search('.//xmlns:referenceList[1]/xmlns:reference'
|
38
|
+
@nodeset.search('.//xmlns:referenceList[1]/xmlns:reference').map do |reference|
|
39
39
|
Placemaker::Reference.new(reference)
|
40
40
|
end
|
41
41
|
end
|
data/lib/placemaker/extents.rb
CHANGED
@@ -8,17 +8,17 @@ module Placemaker
|
|
8
8
|
|
9
9
|
# coordinates of center (WGS84)
|
10
10
|
def center
|
11
|
-
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:center'
|
11
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:center'))
|
12
12
|
end
|
13
13
|
|
14
14
|
# coordinates of southwest corner of bounding box (WGS84)
|
15
15
|
def south_west
|
16
|
-
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:southWest'
|
16
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:southWest'))
|
17
17
|
end
|
18
18
|
|
19
19
|
# coordinates of northeast corner of bounding box (WGS84)
|
20
20
|
def north_east
|
21
|
-
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:northEast'
|
21
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:northEast'))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
data/lib/placemaker/location.rb
CHANGED
@@ -23,13 +23,13 @@ module Placemaker
|
|
23
23
|
|
24
24
|
# centroid for the place
|
25
25
|
def centroid
|
26
|
-
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:centroid'
|
26
|
+
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:centroid'))
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
30
|
|
31
31
|
def nested_node(name)
|
32
|
-
@nodeset.search(".//xmlns:#{name}"
|
32
|
+
@nodeset.search(".//xmlns:#{name}").inner_text
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -6,7 +6,7 @@ module Placemaker
|
|
6
6
|
|
7
7
|
# Returns a Placemaker::Location object as a container for place information.
|
8
8
|
def place
|
9
|
-
Placemaker::Location.new(@nodeset.search('.//xmlns:place'
|
9
|
+
Placemaker::Location.new(@nodeset.search('.//xmlns:place'))
|
10
10
|
end
|
11
11
|
|
12
12
|
# type of match (0=text or text and coordinates, 1=coordinates only)
|
@@ -6,7 +6,7 @@ module Placemaker
|
|
6
6
|
|
7
7
|
# Returns the inner text of a node with the given name under the current @nodeset
|
8
8
|
def nested_node(name)
|
9
|
-
@nodeset.search(".//xmlns:#{name}"
|
9
|
+
@nodeset.search(".//xmlns:#{name}").inner_text
|
10
10
|
end
|
11
11
|
|
12
12
|
private :nested_node
|
@@ -3,23 +3,22 @@ require 'placemaker/document'
|
|
3
3
|
module Placemaker
|
4
4
|
class XmlParser
|
5
5
|
def initialize(xml_body)
|
6
|
-
@body = xml_body
|
7
6
|
@xml = Nokogiri::XML(xml_body)
|
8
7
|
end
|
9
8
|
|
10
9
|
# time in seconds to process the document
|
11
10
|
def processing_time
|
12
|
-
@xml.xpath('.//xmlns:processingTime'
|
11
|
+
@xml.xpath('.//xmlns:processingTime').inner_text.to_f
|
13
12
|
end
|
14
13
|
|
15
14
|
# version of the software used to process the document
|
16
15
|
def version
|
17
|
-
@xml.xpath('.//xmlns:version'
|
16
|
+
@xml.xpath('.//xmlns:version').inner_text.strip
|
18
17
|
end
|
19
18
|
|
20
19
|
# length in bytes of the document
|
21
20
|
def document_length
|
22
|
-
@xml.xpath('.//xmlns:documentLength'
|
21
|
+
@xml.xpath('.//xmlns:documentLength').inner_text.to_i
|
23
22
|
end
|
24
23
|
|
25
24
|
# Returns a set of Placemaker::Document objects as containers for content location information
|
@@ -2,10 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Placemaker::Coordinates do
|
4
4
|
before do
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@coords = @doc.place_details.first.place.centroid
|
5
|
+
xmlp = Placemaker::XmlParser.new(File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])))
|
6
|
+
doc = xmlp.documents[5]
|
7
|
+
@coords = doc.place_details.first.place.centroid
|
9
8
|
end
|
10
9
|
|
11
10
|
it "should be a Placemaker::Coordinates object" do
|
@@ -2,9 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Placemaker::Document do
|
4
4
|
before do
|
5
|
-
|
6
|
-
@
|
7
|
-
@doc = @xmlp.documents[5]
|
5
|
+
xmlp = Placemaker::XmlParser.new(File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])))
|
6
|
+
@doc = xmlp.documents[5]
|
8
7
|
end
|
9
8
|
|
10
9
|
describe "#places" do
|
@@ -2,10 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Placemaker::Extents do
|
4
4
|
before do
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@extents = @doc.extents
|
5
|
+
xmlp = Placemaker::XmlParser.new(File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])))
|
6
|
+
doc = xmlp.documents[5]
|
7
|
+
@extents = doc.extents
|
9
8
|
end
|
10
9
|
|
11
10
|
it "should be a Placemaker::Extents object" do
|
@@ -2,10 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Placemaker::Location do
|
4
4
|
before do
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@loc = @doc.place_details.first.place
|
5
|
+
xmlp = Placemaker::XmlParser.new(File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])))
|
6
|
+
doc = xmlp.documents[5]
|
7
|
+
@loc = doc.place_details.first.place
|
9
8
|
end
|
10
9
|
|
11
10
|
describe "#woe_id" do
|
@@ -2,10 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Placemaker::PlaceDetails do
|
4
4
|
before do
|
5
|
-
|
6
|
-
|
7
|
-
@
|
8
|
-
@pd = @doc.place_details.first
|
5
|
+
xmlp = Placemaker::XmlParser.new(File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])))
|
6
|
+
doc = xmlp.documents[5]
|
7
|
+
@pd = doc.place_details.first
|
9
8
|
end
|
10
9
|
|
11
10
|
describe "#match_type" do
|
@@ -2,8 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Placemaker::Reference do
|
4
4
|
before do
|
5
|
-
|
6
|
-
xmlp = Placemaker::XmlParser.new(xml_str)
|
5
|
+
xmlp = Placemaker::XmlParser.new(File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])))
|
7
6
|
doc = xmlp.documents[5]
|
8
7
|
@reference = doc.reference_list.first
|
9
8
|
end
|
@@ -2,8 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Placemaker::XmlParser do
|
4
4
|
before do
|
5
|
-
|
6
|
-
@xmlp = Placemaker::XmlParser.new(
|
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
7
|
end
|
8
8
|
|
9
9
|
describe "processing_time" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: placemaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Leitgeb
|