9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/woefoo/town_match_validators.rb', line 9
def default_validators
[{
:conditions => Proc.new {|response|
true },
:validator => Proc.new {|response|
best_match=nil
if response.input_quality >= min_input_quality
response.results.each do |r|
if r[:quality] >= response.input_quality && r[:quality] >= min_result_quality
place=Woefoo::GeoplanetPlace.find_by_woeid(r[:woeid])
if place
if place.place_type=="Town"
next if (response.query_options.include?(:country_code) &&
response.query_options[:country_code].downcase != place.country_code.downcase)
best_match=r[:woeid]
elsif ["Zip", "Suburb"].include?(place.place_type) && place.town
next if (response.query_options.include?(:country_code) &&
response.query_options[:country_code].downcase != place.country_code.downcase)
best_match=place.town.woeid
end
else
puts "Encountered a woeid without a geoplanet place #{r[:woeid]}"
end
end
break if best_match
end
end
best_match
}
}]
end
|