Reputation: 13388
Using Rails/Ruby. I have the following:
def normalize
rg = ReverseGeocoder.new(lat, lng, LOCALITY).process!
return save_normalized_values(rg) if rg[:results].any?
rg = ReverseGeocoder.new(lat, lng, ADMINISTRATIVE_AREA_LEVEL_1).process!
return save_normalized_values(rg) if rg[:results].any?
end
While this works, is there a better way to write this?
Upvotes: 1
Views: 48
Reputation: 2345
If you could make .process!
return false on a failure you could do this
rg = ReverseGeocoder.new(lat, lng, LOCALITY).process! || ReverseGeocoder.new(lat, lng, ADMINISTRATIVE_AREA_LEVEL_1).process!
save_normalized_values(rg) if rg[:results].any?
Otherwise I don't see a cleaner way, just different:
rg = ReverseGeocoder.new(lat, lng, LOCALITY).process!
rg[:results] || rg = ReverseGeocoder.new(lat, lng, ADMINISTRATIVE_AREA_LEVEL_1).process!
rg[:results] && save_normalized_values(rg)
Upvotes: 1