diff --git a/lib/bolognese/readers/datacite_reader.rb b/lib/bolognese/readers/datacite_reader.rb index 28b1bc61..c81de246 100644 --- a/lib/bolognese/readers/datacite_reader.rb +++ b/lib/bolognese/readers/datacite_reader.rb @@ -237,7 +237,9 @@ def read_datacite(string: nil, **options) "southBoundLatitude" => gl.dig("geoLocationBox", "southBoundLatitude"), "northBoundLatitude" => gl.dig("geoLocationBox", "northBoundLatitude") }.compact.presence, - "geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon", "polygonPoint")).map { |glp| { "polygonPoint" => glp } }.compact.presence, + "geoLocationPolygon" => Array.wrap(gl.dig("geoLocationPolygon")).map do |glp| + Array.wrap(glp.dig("polygonPoint")).map { |glpp| { "polygonPoint" => glpp } }.compact.presence + end, "geoLocationPlace" => parse_attributes(gl["geoLocationPlace"], first: true).to_s.strip.presence }.compact end diff --git a/spec/fixtures/datacite-geolocationpolygons-multiple.xml b/spec/fixtures/datacite-geolocationpolygons-multiple.xml new file mode 100644 index 00000000..e5e3bf6f --- /dev/null +++ b/spec/fixtures/datacite-geolocationpolygons-multiple.xml @@ -0,0 +1,56 @@ + + +10.5072/multiplegeopolygons + + + John Smithy + + + + Multiple Geopolygon testing + + XML + DataCite + 2021 + + + + + 41 + 71 + + + 45 + 75 + + + 55 + 85 + + + 41 + 71 + + + + + 65 + 80 + + + 55 + 75 + + + 45 + 73 + + + 65 + 80 + + + + + diff --git a/spec/readers/datacite_reader_spec.rb b/spec/readers/datacite_reader_spec.rb index 0b7f4b21..533bdf07 100644 --- a/spec/readers/datacite_reader_spec.rb +++ b/spec/readers/datacite_reader_spec.rb @@ -1545,4 +1545,26 @@ expect(subject.formats.first).to eq("application/xml") end + it "Parsing multiple geolocationpolygon elements" do + input = fixture_path + "datacite-geolocationpolygons-multiple.xml" + subject = Bolognese::Metadata.new(input: input) + expect(subject.valid?).to be true + expect(subject.id).to eq("https://doi.org/10.5072/multiplegeopolygons") + expect(subject.geo_locations).to eq([ + { "geoLocationPolygon"=> [ + [ {"polygonPoint"=>{"pointLatitude"=>"71", "pointLongitude"=>"41"}}, + {"polygonPoint"=>{"pointLatitude"=>"75", "pointLongitude"=>"45"}}, + {"polygonPoint"=>{"pointLatitude"=>"85", "pointLongitude"=>"55"}}, + {"polygonPoint"=>{"pointLatitude"=>"71", "pointLongitude"=>"41"}}], + [ + {"polygonPoint"=>{"pointLatitude"=>"80", "pointLongitude"=>"65"}}, + {"polygonPoint"=>{"pointLatitude"=>"75", "pointLongitude"=>"55"}}, + {"polygonPoint"=>{"pointLatitude"=>"73", "pointLongitude"=>"45"}}, + {"polygonPoint"=>{"pointLatitude"=>"80", "pointLongitude"=>"65"}} + ] + ] } + ] + ) + end + end