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

latitude[R]
longitude[R]

Public Class Methods

new(*args) click to toggle source

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 30
def initialize(*args)
  case args.length
  when 1
    raise ArgumentError, "Can't construct GeoLocationPoint from arguments: #{args}" unless args[0].respond_to?(:keys)

    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

<=>(other) click to toggle source

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 69
def <=>(other)
  return nil unless other.instance_of?(self.class)

  %i[latitude longitude].each do |c|
    order = send(c) <=> other.send(c)
    return order if order.nonzero?
  end
  0
end
hash() click to toggle source

Returns a hash code consistent with {GeoLocationPoint#&lt;=&gt;} @return [Integer] the hash code

# File lib/datacite/mapping/geo_location_point.rb, line 81
def hash
  [latitude, longitude].hash
end
latitude=(value) click to toggle source
# File lib/datacite/mapping/geo_location_point.rb, line 44
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
longitude=(value) click to toggle source
# File lib/datacite/mapping/geo_location_point.rb, line 51
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
to_s() click to toggle source

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 61
def to_s
  "#{latitude} #{longitude}"
end

Private Instance Methods

init_from_array(args) click to toggle source
# File lib/datacite/mapping/geo_location_point.rb, line 92
def init_from_array(args)
  self.latitude, self.longitude = args
end
init_from_hash(latitude:, longitude:) click to toggle source
# File lib/datacite/mapping/geo_location_point.rb, line 87
def init_from_hash(latitude:, longitude:)
  self.latitude = latitude
  self.longitude = longitude
end