Module: Stanford::Mods::GeoUtils
- Included in:
- Coordinate
- Defined in:
- lib/stanford-mods/geo_utils.rb
Overview
Abstract geo methods usable to several classes
Instance Method Summary collapse
-
#cleaner_coordinate(val) ⇒ String
Cleaned value (strips parens and period), or the original value.
-
#coord_to_decimal(point) ⇒ Float
Converted value in decimal notation.
Instance Method Details
#cleaner_coordinate(val) ⇒ String
Returns cleaned value (strips parens and period), or the original value.
8 9 10 11 |
# File 'lib/stanford-mods/geo_utils.rb', line 8 def cleaner_coordinate(val) matches = val.match(/^\(?([^)]+)\)?\.?$/) matches ? matches[1] : val end |
#coord_to_decimal(point) ⇒ Float
Returns converted value in decimal notation.
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/stanford-mods/geo_utils.rb', line 15 def coord_to_decimal(point) regex = /(?<dir>[NESW])\s*(?<deg>\d+)[°⁰º](?:(?<min>\d+)[ʹ'])?(?:(?<sec>\d+)[ʺ"])?/ match = regex.match(point) return Float::INFINITY unless match dec = match['deg'].to_i dec += match['min'].to_f / 60 dec += match['sec'].to_f / 60 / 60 dec = -1 * dec if match['dir'] == 'W' || match['dir'] == 'S' dec end |