Преглед на файлове

fix: get_info_from_address address & post_code

ANX преди 6 години
родител
ревизия
c402d31c3b
променени са 2 файла, в които са добавени 14 реда и са изтрити 4 реда
  1. 13 3
      lib/taiwan_city.rb
  2. 1 1
      lib/taiwan_city/version.rb

+ 13 - 3
lib/taiwan_city.rb

@@ -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

+ 1 - 1
lib/taiwan_city/version.rb

@@ -1,3 +1,3 @@
 module TaiwanCity
-  VERSION = "0.0.5"
+  VERSION = "0.1.3"
 end