Created
July 27, 2016 01:15
-
-
Save 328/0306ed1492ead9638ecff4476b17c8f2 to your computer and use it in GitHub Desktop.
住所を'都道府県市町村'と'番号'に分けるrubyコード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'zip_code_jp' | |
| post_code = '903-2123' #郵便番号 | |
| input_address = '沖縄県なんとか市なんとか町3-121' #住所 | |
| address = ZipCodeJp.find post_code | |
| string = "#{address.prefecture}#{address.city}#{address.town}" | |
| if input_address.include?(string) == true then | |
| input_address.slice!(string) | |
| p input_address | |
| else | |
| p "------------------------------" | |
| p "住所と郵便番号が一致しませんでした" | |
| p "郵便番号: #{post_code}" | |
| p "取り込んだ住所: #{input_address}" | |
| p "郵便番号から得た住所: #{string}" | |
| p "------------------------------" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment