forked from jsl/placemaker
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
301 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Placemaker | ||
class Coordinates | ||
include Placemaker::XmlHelper | ||
|
||
def lat | ||
@nodeset.search('.//xmlns:latitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f | ||
end | ||
|
||
def lng | ||
@nodeset.search('.//xmlns:longitude', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text.to_f | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,31 @@ | ||
module Placemaker | ||
|
||
class Document | ||
def initialize(nodeset) | ||
@nodeset = nodeset | ||
end | ||
include Placemaker::XmlHelper | ||
|
||
def places | ||
# Returns a Placemaker::Location object that is a container for one named place mentioned in the document | ||
def place_details | ||
@nodeset.search('.//xmlns:placeDetails', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').map do |p| | ||
Placemaker::Place.new(p) | ||
Placemaker::PlaceDetails.new(p) | ||
end | ||
end | ||
|
||
# Returns a Placemaker::Location object that is a container for the smallest administrative place that best describes the document | ||
def administrative_scope | ||
as = @nodeset.search('.//xmlns:administrativeScope', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').first | ||
Placemaker::Location.new(as) unless as.nil? | ||
end | ||
|
||
# Returns a Placemaker::Location object that is a container for the smallest place that best describes the document | ||
def geographic_scope | ||
gs = @nodeset.search('.//xmlns:geographicScope', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').first | ||
Placemaker::Location.new(gs) unless gs.nil? | ||
end | ||
|
||
def extents | ||
extents = @nodeset.search('.//xmlns:extents', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').first | ||
Placemaker::Extents.new(extents) unless extents.nil? | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Placemaker | ||
|
||
# container for the the map extents covering the places mentioned in the document | ||
class Extents | ||
include Placemaker::XmlHelper | ||
|
||
# coordinates of center (WGS84) | ||
def center | ||
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:center', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema')) | ||
end | ||
|
||
# coordinates of southwest corner of bounding box (WGS84) | ||
def south_west | ||
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:southWest', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema')) | ||
end | ||
|
||
# coordinates of northeast corner of bounding box (WGS84) | ||
def north_east | ||
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:northEast', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema')) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Placemaker | ||
|
||
# Parses and contains data for +place+, +administrative scope+ and +geographic scope+ elements. | ||
class Location | ||
include Placemaker::XmlHelper | ||
|
||
# permanent identifier for the place | ||
def woe_id | ||
nested_node('woeId').to_i | ||
end | ||
|
||
# fully qualified name for the place | ||
def name | ||
nested_node('name') | ||
end | ||
|
||
# place type name for the place | ||
def location_type | ||
nested_node('type') | ||
end | ||
|
||
# centroid for the place | ||
def centroid | ||
Placemaker::Coordinates.new(@nodeset.search('.//xmlns:centroid', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema')) | ||
end | ||
|
||
private | ||
|
||
def nested_node(name) | ||
@nodeset.search(".//xmlns:#{name}", 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Placemaker | ||
|
||
# container for one named place mentioned in the document | ||
class PlaceDetails | ||
include Placemaker::XmlHelper | ||
|
||
# Returns a Placemaker::Location object as a container for place information. | ||
def place | ||
Placemaker::Location.new(@nodeset.search('.//xmlns:place', 'xmlns' => 'http://wherein.yahooapis.com/v1/schema')) | ||
end | ||
|
||
# type of match (0=text or text and coordinates, 1=coordinates only) | ||
def match_type | ||
nested_node('matchType').to_i | ||
end | ||
|
||
# relative weight of the place within the document (range 1-100) | ||
def weight | ||
nested_node('weight').to_i | ||
end | ||
|
||
# confidence that the document mentions the place (range 1-10) | ||
def confidence | ||
nested_node('confidence').to_i | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Placemaker | ||
module XmlHelper | ||
def initialize(nodeset) | ||
@nodeset = nodeset | ||
end | ||
|
||
# Returns the inner text of a node with the given name under the current @nodeset | ||
def nested_node(name) | ||
@nodeset.search(".//xmlns:#{name}", 'xmlns' => 'http://wherein.yahooapis.com/v1/schema').inner_text | ||
end | ||
|
||
private :nested_node | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require File.join(File.dirname(__FILE__), '..', 'spec_helper') | ||
|
||
describe Placemaker::Coordinates do | ||
before do | ||
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])) | ||
@xmlp = Placemaker::XmlParser.new(@xml_str) | ||
@doc = @xmlp.documents[5] | ||
@coords = @doc.place_details.first.place.centroid | ||
end | ||
|
||
it "should be a Placemaker::Coordinates object" do | ||
@coords.should be_a(Placemaker::Coordinates) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require File.join(File.dirname(__FILE__), '..', 'spec_helper') | ||
|
||
describe Placemaker::Extents do | ||
before do | ||
@xml_str = File.read(File.join(File.dirname(__FILE__), %w[.. fixtures xml_rss_feed_result.xml])) | ||
@xmlp = Placemaker::XmlParser.new(@xml_str) | ||
@doc = @xmlp.documents[5] | ||
@extents = @doc.extents | ||
end | ||
|
||
it "should be a Placemaker::Extents object" do | ||
@extents.should be_a(Placemaker::Extents) | ||
end | ||
|
||
describe "#center" do | ||
it "should return a Placemaker::Point object" do | ||
@extents.center.should be_a(Placemaker::Coordinates) | ||
end | ||
|
||
it "should have a lat of 38.8913" do | ||
@extents.center.lat.should == 38.8913 | ||
end | ||
|
||
it "should have a lng of -77.0337" do | ||
@extents.center.lng.should == -77.0337 | ||
end | ||
end | ||
|
||
describe "#south_west" do | ||
it "should return a Placemaker::Point object" do | ||
@extents.south_west.should be_a(Placemaker::Coordinates) | ||
end | ||
|
||
it "should have a lat of 18.9108" do | ||
@extents.south_west.lat.should == 18.9108 | ||
end | ||
|
||
it "should have a lng of -167.276" do | ||
@extents.south_west.lng.should == -167.276 | ||
end | ||
end | ||
|
||
describe "#north_east" do | ||
it "should return a Placemaker::Point object" do | ||
@extents.north_east.should be_a(Placemaker::Coordinates) | ||
end | ||
|
||
it "should have a lat of 72.8961" do | ||
@extents.north_east.lat.should == 72.8961 | ||
end | ||
|
||
it "should have a lng of -66.6879" do | ||
@extents.north_east.lng.should == -66.6879 | ||
end | ||
end | ||
end |
Oops, something went wrong.