lib/datacite/mapping/geo_location_box.rb in datacite-mapping-0.1.17.2 vs lib/datacite/mapping/geo_location_box.rb in datacite-mapping-0.2.0

- old
+ new

@@ -1,6 +1,7 @@ require 'xml/mapping' +require 'datacite/mapping/geo_location_node' module Datacite module Mapping # A latitude-longitude quadrangle containing the area where the data was gathered or about # which the data is focused. @@ -93,11 +94,11 @@ # {GeoLocationBox} def <=>(other) return nil unless other.class == self.class [:south_latitude, :west_longitude, :north_latitude, :east_longitude].each do |c| order = send(c) <=> other.send(c) - return order if order != 0 + return order if order.nonzero? end 0 end # Returns a hash code consistent with {GeoLocationBox#&lt;=&gt;} @@ -120,16 +121,17 @@ self.west_longitude, self.east_longitude = [coordinates[1], coordinates[3]].sort end end # XML mapping node for `<geoLocationBox/>` - class GeoLocationBoxNode < XML::MappingExtensions::NodeBase - # Converts a whitespace-separated list of coordinates to a {GeoLocationBox}. - # @param xml_text [String] the coordinates, in the order `lat long lat long`. - def to_value(xml_text) - stripped = xml_text.strip - coords = stripped.split(/\s+/).map(&:to_f) - GeoLocationBox.new(*coords) + class GeoLocationBoxNode < GeoLocationNode + def initialize(*args) + @geom_class = GeoLocationBox + @coord_elements = { west_longitude: 'westBoundLongitude', + east_longitude: 'eastBoundLongitude', + south_latitude: 'southBoundLatitude', + north_latitude: 'northBoundLatitude' }.freeze + super end end XML::Mapping.add_node_class GeoLocationBoxNode end