Class: CocinaDisplay::Geospatial::BoundingBoxParser

Inherits:
CoordinatesParser show all
Defined in:
lib/cocina_display/geospatial.rb

Overview

Base class for bounding box parsers.

Constant Summary

Constants inherited from CoordinatesParser

CoordinatesParser::PATTERN

Class Method Summary collapse

Methods inherited from CoordinatesParser

supports?

Class Method Details

.parse(input_str) ⇒ BoundingBox?

Parse the input string into a BoundingBox, or nil if parsing fails.

Parameters:

  • input_str (String)

Returns:



294
295
296
297
298
299
300
301
302
303
304
# File 'lib/cocina_display/geospatial.rb', line 294

def self.parse(input_str)
  matches = input_str.match(self::PATTERN)
  return unless matches

  min_lng = normalize_coord(matches[:min_lng])
  max_lng = normalize_coord(matches[:max_lng])
  min_lat = normalize_coord(matches[:min_lat])
  max_lat = normalize_coord(matches[:max_lat])

  BoundingBox.from_coords(west: min_lng, east: max_lng, north: min_lat, south: max_lat)
end