module ContactInfoHelper def contact_info_for(contactable) contact_info( name: contactable.name, address: contactable.address, phone: contactable.phone, email: contactable.email, ) end def contact_info(name: nil, address: nil, phone: nil, email: nil) content_tag :address do if name.present? concat content_tag(:strong, name) concat tag(:br) end if address.present? concat format_address(address) concat tag(:br) end if phone.present? concat phone_abbr(phone) concat tag(:br) end if email.present? concat email_abbr(email) concat tag(:br) end end end private def format_address(address) case address when Address simple_format address.to_s(format: :condensed), {}, wrapper_tag: "span" else address.to_s end end def email_abbr(email) content_tag(:abbr, "E: ", title: "Email") + mail_to(email) end def phone_abbr(phone) content_tag(:abbr, "P: ", title: "Phone") + phone end end