lib/data_maker/cn/address.rb in data_maker-2.3.3 vs lib/data_maker/cn/address.rb in data_maker-2.3.4

- old
+ new

@@ -67,21 +67,19 @@ [unit_no, street_name, street_suffix].join end def address_string generate - translate build_address end def address_struct generate - translate OpenStruct.new(street_address: street_address, - city: city, - district: district, - province: province, + city: translate('city', city), + district: translate('district', district), + province: translate('province', province), postal_code: postal_code ) end def postal_code @@ -94,16 +92,13 @@ postal_code end private - def translate + def translate(prefix, value) DataMaker::Config.locale = locale - values = { province: province, city: city, district: district } - values.each do |key, value| - self.send("#{key}=", DataMaker.translate(['data_maker', 'address', key, value].join("."))) - end + DataMaker.translate(['data_maker', 'address', prefix, value].join(".")) end def validate if province unless province_exists? @@ -153,12 +148,12 @@ end def build_address address = [] address << street_address - address << city - address << district - address << province + address << translate('city', city) + address << translate('district', district) unless district.nil? + address << translate('province', province) address << postal_code address.compact.join(", ") end def street_name