Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_calc/extensions/string.rb

Instance Method Summary collapse

Instance Method Details

#geo_cleanObject



10
11
12
# File 'lib/geo_calc/extensions/string.rb', line 10

def geo_clean
  self.gsub(/^\(/, '').gsub(/\)$/, '').trim
end

#to_latObject



26
27
28
29
30
31
# File 'lib/geo_calc/extensions/string.rb', line 26

def to_lat
  raise "An empty String has no latitude" if self.empty?
  s = geo_clean
  s = s.parse_dms if s.respond_to? :parse_dms
  s.to_f.to_lat
end

#to_lat_lngObject



14
15
16
17
18
# File 'lib/geo_calc/extensions/string.rb', line 14

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_lngObject



33
34
35
36
37
38
# File 'lib/geo_calc/extensions/string.rb', line 33

def to_lng
  raise "An empty String has no latitude" if self.empty?
  s = geo_clean
  s = s.parse_dms if s.respond_to? :parse_dms    
  s.to_f.to_lng
end

#to_lng_latObject



20
21
22
23
24
# File 'lib/geo_calc/extensions/string.rb', line 20

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_radObject



2
3
4
# File 'lib/geo_calc/extensions/string.rb', line 2

def to_rad
  parse_dms.to_rad
end

#trimObject



6
7
8
# File 'lib/geo_calc/extensions/string.rb', line 6

def trim
  strip
end