|
@@ -39,7 +39,12 @@ module TaiwanCity
|
|
|
def get_info_from_address(address)
|
|
|
return '' if address.blank?
|
|
|
address.gsub!('臺', '台')
|
|
|
- addr = {}
|
|
|
+ addr = {
|
|
|
+ city_code:'', city: '',
|
|
|
+ dist_code:'', dist: '',
|
|
|
+ post_code:'', address: '',
|
|
|
+ full_address: ''
|
|
|
+ }
|
|
|
data.each do |city_code, city|
|
|
|
next if address.exclude?(city[:text])
|
|
|
addr[:city] = city[:text]
|
|
@@ -48,12 +53,17 @@ module TaiwanCity
|
|
|
next if address.exclude?(dist[:text])
|
|
|
addr[:dist] = dist[:text]
|
|
|
addr[:dist_code] = dist_code
|
|
|
- addr[:post_code] = dist_code[2..5]
|
|
|
+ addr[:post_code] = dist_code[2..4]
|
|
|
break
|
|
|
end
|
|
|
break
|
|
|
end
|
|
|
- addr[:address] = address.gsub(addr[:city], '').gsub(addr[:dist], '')
|
|
|
+
|
|
|
+ dist_position = address.index(addr[:dist]) ? address.index(addr[:dist]) + addr[:dist].size : nil
|
|
|
+ city_position = address.index(addr[:city]) ? address.index(addr[:city]) + addr[:city].size : nil
|
|
|
+ del_position = dist_position || city_position || 0
|
|
|
+ addr[:address] = address[del_position..-1]
|
|
|
+
|
|
|
addr[:full_address] = address
|
|
|
addr
|
|
|
end
|