Sha256: 50779adb894b476f7f4d308a6f741cb0105486d1ae2e1136010583424ec0814c
Contents?: true
Size: 1.16 KB
Versions: 3
Compression:
Stored size: 1.16 KB
Contents
# coding: utf-8 module GyomuRuby module OrdinarySystemDevelopment module AddressFormatter PREFS = File.read( File.expand_path('../../../masters/prefectures.csv', File.dirname(__FILE__)) ).lines.map(&:strip).freeze ext_tel_numbers = File.read( File.expand_path('../../../masters/ext_tel_numbers.csv', File.dirname(__FILE__)) ).lines.map{|n| "0#{n.strip}" } EXT_TEL_NUMBERS = (ext_tel_numbers + %w[050 070 080 090 0120]).sort.reverse.freeze EXT_TEL_NUMBERS_RE = /\A(#{EXT_TEL_NUMBERS.sort.reverse.join('|')})/uo module_function def format_zipcode(zipcode_string, blank = '') return blank if zipcode_string.blank? zipcode_string.sub(/\A(\d{3})(\d{4})\Z/){ "#{$1}-#{$2}" } end def format_tel_no(telno_numeric_string, blank = '') return blank if telno_numeric_string.blank? telno_numeric_string.to_s. sub(EXT_TEL_NUMBERS_RE){ "#{$1}-" }. sub(/(\d{4})\Z/) { "-#{$1}" } end def prefecture_name(prefecture_code, blank = '') return blank if prefecture_code.blank? PREFS[prefecture_code.to_i - 1] end end end end
Version data entries
3 entries across 3 versions & 1 rubygems