class Datacite::Mapping::GeoLocationPolygon

Constants

COORD_ELEMENTS

TODO: Figure out how to DRY this with GeoLocationPointNode

Public Class Methods

marshal_point(element, value) click to toggle source
# File lib/datacite/mapping/geo_location_polygon.rb, line 68
def self.marshal_point(element, value)
  COORD_ELEMENTS.each do |getter, element_name|
    v = value.send(getter)
    child = element.elements << REXML::Element.new(element_name)
    child.text = v
  end
end
new(points:, in_polygon_point: nil) click to toggle source

Creates a new ‘GeoLocationPolygon`.

@param points [Array<GeoLocationPoint>] an array of points defining the polygon area.

Per the spec, the array should contain at least four points, the first and last being
identical to close the polygon.
# File lib/datacite/mapping/geo_location_polygon.rb, line 16
def initialize(points:, in_polygon_point: nil) # TODO: allow simple array of point args, array of hashes
  self.points = points
  self.in_polygon_point = in_polygon_point
  warn "Polygon should contain at least 4 points, but has #{points.size}" if points.size < 4
  warn "Polygon is not closed; last and first point should be identical, but were: [#{points[0]}], [#{points[-1]}]" unless points[0] == points[-1] || points.size <= 1
end
unmarshal_point(elem) click to toggle source
# File lib/datacite/mapping/geo_location_polygon.rb, line 76
def self.unmarshal_point(elem)
  coords_hash = COORD_ELEMENTS.map do |key, element_name|
    value = elem.elements[element_name].text
    [key, value && value.to_f]
  end.to_h
  GeoLocationPoint.new(coords_hash)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/datacite/mapping/geo_location_polygon.rb, line 27
def <=>(other)
  return nil unless other.instance_of?(self.class)

  points <=> other.points
end
hash() click to toggle source
# File lib/datacite/mapping/geo_location_polygon.rb, line 33
def hash
  points.hash
end
points=(value) click to toggle source
# File lib/datacite/mapping/geo_location_polygon.rb, line 23
def points=(value)
  @points = value || []
end
to_s() click to toggle source
# File lib/datacite/mapping/geo_location_polygon.rb, line 37
def to_s
  point_hashes = points.map { |p| "{ latitude: #{p.latitude}, longitude: #{p.longitude} }" }.join(', ')
  "[ #{point_hashes} ]"
end