Sha256: b3d95746fae86864751cd9c3b72d81bc04af3ffe77ddd423ea6d5b3c60d35a16
Contents?: true
Size: 1.11 KB
Versions: 2
Compression:
Stored size: 1.11 KB
Contents
class GeoDirectionMisMatch < StandardError; end; class String def to_rad parse_dms.to_rad end def trim strip end def geo_clean self.gsub(/^\(/, '').gsub(/\)$/, '').trim end def to_lat_lng a = geo_clean.split(',').map(&:strip) a = (a.last.is_a?(String) && a.last =~ /[N|S]$/) ? a.reverse : a a.to_lat_lng end def to_lng_lat a = geo_clean.split(',') a = (a.last.is_a?(String) && a.last =~ /[N|S]$/) ? a.reverse : a a.to_lng_lat end def to_lat raise "An empty String has no latitude" if self.empty? s = geo_clean raise GeoDirectionMisMatch, "Direction E and W signify longitude and thus can't be converted to latitude, was: #{self}" if s =~ /[W|E]$/ s = s.parse_dms if s.respond_to? :parse_dms s.to_f.to_lat end def to_lng raise "An empty String has no latitude" if self.empty? s = geo_clean raise GeoDirectionMisMatch, "Direction N and S signify latitude and thus can't be converted to longitude, was: #{self}" if s =~ /[N|S]$/ s = s.parse_dms if s.respond_to? :parse_dms s.to_f.to_lng end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
geo_calc-0.7.7 | lib/geo_calc/extensions/string.rb |
geo_calc-0.7.6 | lib/geo_calc/extensions/string.rb |