class Datacite::Mapping::GeoLocationPoint
A latitude-longitude point at which the data was gathered or about which the data is focused.
@!attribute [rw] latitude
@return [Numeric] the latitude
@!attribute [rw] longitude
@return [Numeric] the longitude
Attributes
Public Class Methods
Initializes a new {GeoLocationPoint}. The arguments can be provided either as a named-parameter hash, or as a pair of coordinates in the form `lat, long`. That is, the following forms are equivalent:
GeoLocationPoint.new(latitude: 47.61, longitude: -122.33) GeoLocationPoint.new(47.61, -122.33)
@param latitude [Numeric] the latitude @param longitude [Numeric] the longitude
# File lib/datacite/mapping/geo_location_point.rb, line 31 def initialize(*args) case args.length when 1 init_from_hash(args[0]) when 2 init_from_array(args) else raise ArgumentError, "Can't construct GeoLocationPoint from arguments: #{args}" end end
Public Instance Methods
Sorts points from north to south and from east to west, and compares them for equality. @param other [GeoLocationPoint] the point to compare @return [Fixnum, nil] the sort order (-1, 0, or 1), or nil if `other` is not a
{GeoLocationPoint}
# File lib/datacite/mapping/geo_location_point.rb, line 67 def <=>(other) return nil unless other.class == self.class %i[latitude longitude].each do |c| order = send(c) <=> other.send(c) return order if order.nonzero? end 0 end
Returns a hash code consistent with {GeoLocationPoint#<=>} @return [Integer] the hash code
# File lib/datacite/mapping/geo_location_point.rb, line 79 def hash [latitude, longitude].hash end
# File lib/datacite/mapping/geo_location_point.rb, line 42 def latitude=(value) raise ArgumentError, 'Latitude cannot be nil' unless value raise ArgumentError, "#{value} is not a valid latitude" unless value >= -90 && value <= 90 @latitude = value end
# File lib/datacite/mapping/geo_location_point.rb, line 49 def longitude=(value) raise ArgumentError, 'Longitude cannot be nil' unless value raise ArgumentError, "#{value} is not a valid longitude" unless value >= -180 && value <= 180 @longitude = value end
Gets the coordinates as a string. @return [String] the coordinates as a pair of numbers separated by a space, in the
order `lat` `long`.
# File lib/datacite/mapping/geo_location_point.rb, line 59 def to_s "#{latitude} #{longitude}" end
Private Instance Methods
# File lib/datacite/mapping/geo_location_point.rb, line 90 def init_from_array(args) self.latitude, self.longitude = args end
# File lib/datacite/mapping/geo_location_point.rb, line 85 def init_from_hash(latitude:, longitude:) self.latitude = latitude self.longitude = longitude end