<commit_before>module Office::AngelsHelper

  def options_for_gender(form)
    choices = [[I18n.t(:'enums.angel.gender.female'), Angel::FEMALE],
               [I18n.t(:'enums.angel.gender.male'), Angel::MALE]]
    { :as => :radio, :label => 'Gender', :required => true,
      :collection => choices}
  end

  def options_for_country(form)
    Carmen.default_locale = I18n.locale
    defaults = if I18n.locale.to_s == 'de'
                 %w(DE AT NL GB)
               else
                 %w(GB)
               end
    { :priority_countries => defaults }
  end
  
  def options_for_lang(form)
    choices = [%w(Deutsch de), %w(English en)]
    { :as => :radio, :label => 'Language', :collection => choices}
  end

  def options_for_angel_select(form)
    { :as => :select, :label => 'Angel', :collection => Angel.by_last_name }
  end
  
  # FIXME this doesn;t work until the address is urlencoded
  def link_to_map(angel)
    "FIXME"
    #link_to('Map', "http://maps.google.com/maps?q=#{compact_address(angel, ',')}", :target => '_blank')
  end

  # return address in html display format
  def compact_address(angel, separator = tag(:br))
    country = (angel.country || "").strip.downcase
    layout = 'UK' if ['uk','england','gb','great britain'].include?(country)
    address = case layout
              when 'UK'
                h(angel.address) + "\n" +
                  h(angel.city) + "\n" +
                  h(angel.postal_code) + "\n" +
                  h(angel.country)
              else
                h(angel.address) + "\n" +
                  h("#{angel.postal_code} #{angel.city}") + "\n" +
                  h(angel.country)
              end
    return '' if address.blank?
    address.gsub("\n", separator).html_safe
  end
  
 
  def compact_phones(angel, separator = tag(:br))
    phones = []
    %w(home mobile work).each do |ph|
      number = angel.read_attribute("#{ph}_phone")
      unless number.blank?
        phones << h("#{ph[0].capitalize}: #{number}")
      end
    end
    phones.join(separator).html_safe
  end

  def angel_controls
    controls do |c|
      add_button_to(c, "Map", params.merge(:action => :map, :icon => 'map_magnify'))
      add_button_to(c, "VCard", params.merge(:format => :vcard, :icon => 'vcard'))
      yield c if block_given?
    end
  end
end<commit_msg>improved compact_address<commit_after>module Office::AngelsHelper

  def options_for_gender(form)
    choices = [[I18n.t(:'enums.angel.gender.female'), Angel::FEMALE],
               [I18n.t(:'enums.angel.gender.male'), Angel::MALE]]
    { :as => :radio, :label => 'Gender', :required => true,
      :collection => choices}
  end

  def options_for_country(form)
    Carmen.default_locale = I18n.locale
    defaults = if I18n.locale.to_s == 'de'
                 %w(DE AT NL GB)
               else
                 %w(GB)
               end
    { :priority_countries => defaults }
  end
  
  def options_for_lang(form)
    choices = [%w(Deutsch de), %w(English en)]
    { :as => :radio, :label => 'Language', :collection => choices}
  end

  def options_for_angel_select(form)
    { :as => :select, :label => 'Angel', :collection => Angel.by_last_name }
  end
  
  # FIXME this doesn;t work until the address is urlencoded
  def link_to_map(angel)
    "FIXME"
    #link_to('Map', "http://maps.google.com/maps?q=#{compact_address(angel, ',')}", :target => '_blank')
  end

  # return address in html display format
  def compact_address(a, separator = tag(:br))
    code = (a.country || Carmen.default_country || '').strip.upcase
    address = if %w(US GB).include?(code)
                h("#{a.address}\n#{a.city}\n#{a.postal_code}")
              elsif %w(AU CA).include?(code)
                h("#{a.address}\n#{a.city} #{a.postal_code}")
              else
                h("#{a.address}\n#{a.postal_code} #{a.city}")
              end
    if code != Carmen.default_country
      address << "\n" + Carmen.country_name(code, :locale => I18n.locale)
    end
    address.gsub("\n", separator).html_safe
  end

  def compact_phones(angel, separator = tag(:br))
    phones = []
    %w(home mobile work).each do |ph|
      number = angel.read_attribute("#{ph}_phone")
      unless number.blank?
        label = t("enums.registration.roster.#{ph}")
        phones << h("#{label}: #{number}")
      end
    end
    phones.join(separator).html_safe
  end
    
  def angel_controls
    controls do |c|
      add_button_to(c, "Map", params.merge(:action => :map, :icon => 'map_magnify'))
      add_button_to(c, "VCard", params.merge(:format => :vcard, :icon => 'vcard'))
      yield c if block_given?
    end
  end
end
{'fraction_non_alphanumeric': 0.15907619253183683, 'fraction_numerical': 0.004101014461472048, 'mean_word_length': 2.502645502645503, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2996669', 'n_tokens_mistral': 1570, 'n_tokens_neox': 1540, 'n_words': 328}