<commit_before>class ApplicationDecorator < Draper::Decorator 
  delegate_all
  include ActionView::Helpers::NumberHelper

  def self.collection_decorator_class
    PaginatingDecorator
  end

  def ass_name(association, extra = '')
    ass = object.send(association, name)
    [ass.name, extra].reject(&:blank?).join(' ') if ass.present?
  end

  def attr_list_item(desc = nil, title, with_colon: false)
    return nil unless desc.present?
    title = "#{title}:" if with_colon
    html = h.content_tag(:span, title, class: 'attr-title')
    h.content_tag(:li, html + desc)
  end


  def dl_list_item(dd = nil, dt)
    return nil unless dd.present?
    html = h.content_tag(:dt, dt)
    html << h.content_tag(:dd, dd)
    html.html_safe
  end

  def dl_from_attribute(attribute, title = nil)
    description = if_present(attribute)
    return nil unless description
    title = attribute.titleize unless title.present?
    self.dl_list_item(description, title)
  end

  def dl_from_attribute_othered(attribute, title = nil)
    description = ass_name(attribute)
    return nil unless description
    if description == "Other style"
      other = if_present("#{attribute}_other")
      description = other if other.present?
    end
    title = attribute.titleize unless title.present?
    self.dl_list_item(description, title)
  end

  def if_present(attribute, action = nil)
    if object.send(attribute).present?
      return action if action.present?
      object.send(attribute)
    end
  end

  def twitterable(user)
    if user.show_twitter and user.twitter
     h.link_to 'Twitter', "https://twitter.com/#{user.twitter}"
    end
  end

  def websiteable(user)
    if user.show_website and user.website
      h.link_to 'Website', user.website
    end
  end

  def show_twitter_and_website(user)
    if twitterable(user) or websiteable(user)
      html = ""
      if twitterable(user)
        html << twitterable(user)
        html << " and #{websiteable(user)}" if websiteable(user)
      else
        html << websiteable(user)
      end
      html.html_safe
    end
  end

  def short_address(item)
    return nil unless item.country
    html = "#{item.city}"
    html << ", #{item.state.abbreviation}" if item.state.present?
    html << " - #{item.country.iso}"
    html
  end

  def display_phone(p=object.phone)
    if p[/\+/]
      phone = number_to_phone(p.gsub(/\+\d*/,''), country_code: p[/\A.\d*/].gsub('+',''), delimiter: ' ' )
    else
      phone = number_to_phone(p, delimiter: ' ')
    end
    phone
  end

end<commit_msg>Minor phone display bugfix (#513)<commit_after>class ApplicationDecorator < Draper::Decorator 
  delegate_all
  include ActionView::Helpers::NumberHelper

  def self.collection_decorator_class
    PaginatingDecorator
  end

  def ass_name(association, extra = '')
    ass = object.send(association, name)
    [ass.name, extra].reject(&:blank?).join(' ') if ass.present?
  end

  def attr_list_item(desc = nil, title, with_colon: false)
    return nil unless desc.present?
    title = "#{title}:" if with_colon
    html = h.content_tag(:span, title, class: 'attr-title')
    h.content_tag(:li, html + desc)
  end


  def dl_list_item(dd = nil, dt)
    return nil unless dd.present?
    html = h.content_tag(:dt, dt)
    html << h.content_tag(:dd, dd)
    html.html_safe
  end

  def dl_from_attribute(attribute, title = nil)
    description = if_present(attribute)
    return nil unless description
    title = attribute.titleize unless title.present?
    self.dl_list_item(description, title)
  end

  def dl_from_attribute_othered(attribute, title = nil)
    description = ass_name(attribute)
    return nil unless description
    if description == "Other style"
      other = if_present("#{attribute}_other")
      description = other if other.present?
    end
    title = attribute.titleize unless title.present?
    self.dl_list_item(description, title)
  end

  def if_present(attribute, action = nil)
    if object.send(attribute).present?
      return action if action.present?
      object.send(attribute)
    end
  end

  def twitterable(user)
    if user.show_twitter and user.twitter
     h.link_to 'Twitter', "https://twitter.com/#{user.twitter}"
    end
  end

  def websiteable(user)
    if user.show_website and user.website
      h.link_to 'Website', user.website
    end
  end

  def show_twitter_and_website(user)
    if twitterable(user) or websiteable(user)
      html = ""
      if twitterable(user)
        html << twitterable(user)
        html << " and #{websiteable(user)}" if websiteable(user)
      else
        html << websiteable(user)
      end
      html.html_safe
    end
  end

  def short_address(item)
    return nil unless item.country
    html = "#{item.city}"
    html << ", #{item.state.abbreviation}" if item.state.present?
    html << " - #{item.country.iso}"
    html
  end

  def display_phone(str = nil)
    str ||= object&.phone
    if str.blank?
      nil
    elsif str[/\+/]
      number_to_phone(str.gsub(/\+\d*/,''), country_code: str[/\A.\d*/].gsub('+',''), delimiter: ' ' )
    else
      number_to_phone(str, delimiter: ' ')
    end
  end
end
{'fraction_non_alphanumeric': 0.11703992210321325, 'fraction_numerical': 0.0005842259006815969, 'mean_word_length': 3.0956937799043063, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2635021', 'n_tokens_mistral': 1696, 'n_tokens_neox': 1631, 'n_words': 398}