Class: CocinaDisplay::Geospatial::CoordinatesParser

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

Overview

Base class for parsers that convert strings into Coordinates objects. Subclasses must define at least the PATTERN constant and self.parse method.

Constant Summary collapse

PATTERN =
nil

Class Method Summary collapse

Class Method Details

.hemisphere_first(value) ⇒ String

Move a trailing hemisphere letter to the front, since that is where the decimal normalizer expects it.

Examples:

"121.5W" becomes "W121.5"

Parameters:

  • value (String)

Returns:

  • (String)


344
345
346
# File 'lib/cocina_display/geospatial.rb', line 344

def self.hemisphere_first(value)
  value.sub(/\A(.+?)([NESW])\z/, '\2\1')
end

.supports?(input_str) ⇒ Boolean

If true, use this parser for the given input string.

Parameters:

  • input_str (String)

Returns:

  • (Boolean)


335
336
337
# File 'lib/cocina_display/geospatial.rb', line 335

def self.supports?(input_str)
  input_str.match?(self::PATTERN)
end