lib/geo_combine/ogp.rb in geo_combine-0.5.1 vs lib/geo_combine/ogp.rb in geo_combine-0.6.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'active_support/core_ext/object/blank' require 'cgi' module GeoCombine # Data model for OpenGeoPortal metadata @@ -75,19 +77,17 @@ dc_type_s: 'Dataset' }.delete_if { |_k, v| v.nil? } end def date - begin - DateTime.rfc3339(metadata['ContentDate']) - rescue - nil - end + DateTime.rfc3339(metadata['ContentDate']) + rescue StandardError + nil end def year - date.year unless date.nil? + date&.year end ## # Convert "Paper Map" to Raster, assumes all OGP "Paper Maps" have WMS def ogp_geom @@ -102,13 +102,13 @@ ## # OGP doesn't ship format types, so we just try and be clever here. def ogp_formats case metadata['DataType'] when 'Paper Map', 'Raster' - return 'GeoTIFF' + 'GeoTIFF' when 'Polygon', 'Point', 'Line' - return 'Shapefile' + 'Shapefile' else raise ArgumentError, metadata['DataType'] end end @@ -126,10 +126,11 @@ raise ArgumentError unless west >= -180 && west <= 180 && east >= -180 && east <= 180 && north >= -90 && north <= 90 && south >= -90 && south <= 90 && west <= east && south <= north + "ENVELOPE(#{west}, #{east}, #{north}, #{south})" end def subjects fgdc.metadata.xpath('//themekey').map(&:text) if fgdc @@ -163,10 +164,11 @@ .reduce({}, :merge) end def download_uri return 'http://schema.org/DownloadAction' if institution == 'Harvard' + 'http://schema.org/downloadUrl' end ## # OGP "Location" field parsed @@ -203,22 +205,22 @@ name = [institution, name].join('-') if institution.present? && !name.downcase.start_with?(institution.downcase) sluggify(filter_name(name)) end - SLUG_BLACKLIST = %w[ + SLUG_STRIP_VALUES = %w[ SDE_DATA. SDE. SDE2. GISPORTAL.GISOWNER01. GISDATA. MORIS. ].freeze def filter_name(name) # strip out schema and usernames - SLUG_BLACKLIST.each do |blacklisted| - name.sub!(blacklisted, '') + SLUG_STRIP_VALUES.each do |strip_val| + name.sub!(strip_val, '') end unless name.size > 1 # use first word of title is empty name name = metadata['LayerDisplayName'].split.first end