Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/geo_calc/extensions/string.rb
Instance Method Summary collapse
- #geo_clean ⇒ Object
- #to_lat ⇒ Object
- #to_lat_lng ⇒ Object
- #to_lng ⇒ Object
- #to_lng_lat ⇒ Object
- #to_rad ⇒ Object
- #trim ⇒ Object
Instance Method Details
#geo_clean ⇒ Object
12 13 14 |
# File 'lib/geo_calc/extensions/string.rb', line 12 def geo_clean self.gsub(/^\(/, '').gsub(/\)$/, '').trim end |
#to_lat ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/geo_calc/extensions/string.rb', line 28 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 rescue GeoUnits::Converter::Dms::ParseError ensure s.to_f.to_lat end |
#to_lat_lng ⇒ Object
16 17 18 19 20 |
# File 'lib/geo_calc/extensions/string.rb', line 16 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 |
#to_lng ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/geo_calc/extensions/string.rb', line 38 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 rescue GeoUnits::Converter::Dms::ParseError ensure s.to_f.to_lng end |
#to_lng_lat ⇒ Object
22 23 24 25 26 |
# File 'lib/geo_calc/extensions/string.rb', line 22 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 |
#to_rad ⇒ Object
4 5 6 |
# File 'lib/geo_calc/extensions/string.rb', line 4 def to_rad parse_dms.to_rad end |
#trim ⇒ Object
8 9 10 |
# File 'lib/geo_calc/extensions/string.rb', line 8 def trim strip end |