lib/datacite/mapping/geo_location_box.rb in datacite-mapping-0.4.1 vs lib/datacite/mapping/geo_location_box.rb in datacite-mapping-0.5.0
- old
+ new
@@ -17,14 +17,11 @@
# @!attribute [rw] east_longitude
# @return [Numeric] the longitude of the east edge of the box
class GeoLocationBox
include Comparable
- attr_reader :south_latitude
- attr_reader :west_longitude
- attr_reader :north_latitude
- attr_reader :east_longitude
+ attr_reader :south_latitude, :west_longitude, :north_latitude, :east_longitude
# Initializes a new {GeoLocationBox}. The arguments can be provided
# either as a named-parameter hash, or as a list of four coordinates
# in the form `lat, long, lat, long` (typically
# `south_latitude, west_longitude, north_latitude, east_longitude`
@@ -49,11 +46,14 @@
# @param east_longitude [Numeric]
# the longitude of the east edge of the box
def initialize(*args)
case args.length
when 1
- init_from_hash(args[0])
+ raise ArgumentError, "Can't construct GeoLocationBox from arguments: #{args}" unless args[0].respond_to?(:keys)
+
+ init_from_hash(**args[0])
+
when 4
init_from_array(args)
else
raise ArgumentError, "Can't construct GeoLocationBox from arguments: #{args}"
end
@@ -97,10 +97,10 @@
# edge, then north edge, then east edge, and compares them for equality.
# @param other [GeoLocationBox] the box to compare
# @return [Fixnum, nil] the sort order (-1, 0, or 1), or nil if `other` is not a
# {GeoLocationBox}
def <=>(other)
- return nil unless other.class == self.class
+ return nil unless other.instance_of?(self.class)
%i[south_latitude west_longitude north_latitude east_longitude].each do |c|
order = send(c) <=> other.send(c)
return order if order.nonzero?
end