20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'app/helpers/workarea/addresses_helper.rb', line 20
def formatted_address(address)
pieces = {
recipient: "#{address.first_name} #{address.last_name}\n#{address.company}".strip,
street: "#{address.street} #{address.street_2}".strip,
city: address.city,
region: address.region_name,
region_short: address.region,
postalcode: address.postal_code,
country: address.country.alpha2
}
address_format = address.country.address_format || Country['US'].address_format
result = pieces.reduce(address_format) do |memo, (name, value)|
memo.gsub(/{{#{name}}}/, html_escape(value.to_s))
end
if address.phone_number.present?
formatted_phone = number_to_phone(
address.phone_number,
extension: address.phone_extension
)
result << "\n#{formatted_phone}"
end
result.gsub(/\n/, tag(:br)).html_safe
end
|