Pr0d1r2-geokit 1.3.2.8 → 1.3.2.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/geokit/cached/model.rb +11 -1
- metadata +1 -1
data/lib/geokit/cached/model.rb
CHANGED
@@ -14,12 +14,13 @@ module Geokit
|
|
14
14
|
|
15
15
|
def cache!(attributes)
|
16
16
|
self.attributes = attributes
|
17
|
+
self.city = convert_to_utf8(self.city)
|
17
18
|
save if new_record? || changed?
|
18
19
|
end
|
19
20
|
|
20
21
|
def update!
|
21
22
|
if !by_google? && geo.success
|
22
|
-
self.lat, self.lng, self.provider, self.city = geo.lat, geo.lng, geo.provider, geo.city
|
23
|
+
self.lat, self.lng, self.provider, self.city = geo.lat, geo.lng, geo.provider, convert_to_utf8(geo.city)
|
23
24
|
save if changed?
|
24
25
|
end
|
25
26
|
end
|
@@ -67,6 +68,15 @@ module Geokit
|
|
67
68
|
!!(lat and lng)
|
68
69
|
end
|
69
70
|
|
71
|
+
def convert_to_utf8(str)
|
72
|
+
begin
|
73
|
+
Iconv.new('UTF-8', 'UTF-8').iconv(str)
|
74
|
+
rescue Iconv::Failure => iconv_exception
|
75
|
+
Iconv.new('UTF-8', 'ISO-8859-1').iconv(str)
|
76
|
+
iconv_exception.success
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
70
80
|
end
|
71
81
|
end
|
72
82
|
end
|