Sha256: a014d8df4d21f8ae3f4d2dcecc92216acc16e1b6b73ac4f60b7dcc7ba35a84b6

Contents?: true

Size: 1.42 KB

Versions: 62

Compression:

Stored size: 1.42 KB

Contents

module Workarea
  module AddressesHelper
    def country_options
      Workarea.config.countries.map do |country|
        [country.name, country.alpha2]
      end
    end

    def region_options
      @region_options ||= Workarea.config.countries.reduce([]) do |memo, country|
        regions = country.subdivisions
                    .map { |id, region| [region.translations[I18n.locale.to_s] || region.name, id] }
                    .sort_by { |name, id| name || id }

        memo << [country.name, regions]
        memo
      end
    end

    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
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.15 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.36 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.14 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.35 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.13 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.34 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.12 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.33 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.11 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.10 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.32 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.9 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.31 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.8 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.30 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.7 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.29 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.6 app/helpers/workarea/addresses_helper.rb
workarea-core-3.4.28 app/helpers/workarea/addresses_helper.rb
workarea-core-3.5.5 app/helpers/workarea/addresses_helper.rb