<commit_before>module PersonalInfo
  extend ActiveSupport::Concern

  def bio
    [gender&.titlecase, current_age&.to_i].compact.join(', ')
  end

  def bio_historic
    [gender.try(:titlecase), age.try(:to_i)].compact.join(', ')
  end

  def country
    @country ||= Carmen::Country.coded(country_code)
  end

  def current_age
    current_age_from_birthdate || (has_attribute?('current_age_from_efforts') ?
                                       attributes['current_age_from_efforts']&.round(0) : current_age_approximate)
  end

  def current_age_from_birthdate
    birthdate && TimeDifference.between(birthdate, Time.now.utc.to_date).in_years.round(0)
  end

  def flexible_geolocation
    [city, flexible_state, flexible_country].compact.join(', ')
  end

  def full_bio
    [bio, flexible_geolocation].compact.join(' • ')
  end

  def full_name
    [first_name.presence, last_name.presence].compact.join(' ')
  end
  alias_method :name, :full_name

  def personal_info
    [full_name, bio, flexible_geolocation].compact.join(' – ')
  end

  def state
    @state ||= country && country.subregions.presence&.coded(state_code)
  end

  def state_and_country
    [state_name, country_name].compact.join(', ')
  end

  module ClassMethods
    def exact_ages_today # Returns a hash of {resource.id => age today} ignoring any resource without a birthdate
      now = Time.now.utc.to_date
      birthdate_hash = Hash[self.where.not(birthdate: nil).pluck(:id, :birthdate)]
      Hash[birthdate_hash.map { |id, birthdate| [id, TimeDifference.between(birthdate, now).in_years.round(0)] }]
    end
  end

  private

  def country_abbreviations
    {'United States' => 'US'}
  end

  def country_name
    @country_name ||= country && (country_abbreviations[country.name] || country.name)
  end

  def flexible_state
    (city || state.nil?) ? state_code : state
  end

  def flexible_country<commit_msg>Tweak PersonalInfo methods to ensure joins are not performed on empty strings.<commit_after>module PersonalInfo
  extend ActiveSupport::Concern

  def bio
    [gender&.titlecase, current_age&.to_i].compact.join(', ')
  end

  def bio_historic
    [gender&.titlecase, age&.to_i].compact.join(', ')
  end

  def country
    @country ||= Carmen::Country.coded(country_code)
  end

  def current_age
    current_age_from_birthdate || (has_attribute?('current_age_from_efforts') ?
                                       attributes['current_age_from_efforts']&.round(0) : current_age_approximate)
  end

  def current_age_from_birthdate
    birthdate && TimeDifference.between(birthdate, Time.now.utc.to_date).in_years.round(0)
  end

  def flexible_geolocation
    [city, flexible_state, flexible_country].select(&:present?).join(', ')
  end

  def full_bio
    [bio, flexible_geolocation].select(&:present?).join(' • ')
  end

  def full_name
    [first_name, last_name].select(&:present?).join(' ')
  end
  alias_method :name, :full_name

  def personal_info
    [full_name, bio, flexible_geolocation].select(&:present?).join(' – ')
  end

  def state
    @state ||= country && country.subregions.presence&.coded(state_code)
  end

  def state_and_country
    [state_name, country_name].select(&:present?).join(', ')
  end

  module ClassMethods
    def exact_ages_today # Returns a hash of {resource.id => age today} ignoring any resource without a birthdate
      now = Time.now.utc.to_date
      birthdate_hash = Hash[self.where.not(birthdate: nil).pluck(:id, :birthdate)]
      Hash[birthdate_hash.map { |id, birthdate| [id, TimeDifference.between(birthdate, now).in_years.round(0)] }]
    end
  end

  private

  def country_abbreviations
    {'United States' => 'US'}
  end

  def country_name
    @country_name ||= country && (country_abbreviations[country.name] || country.name)
  end

  def flexible_state
    (city || state.nil?) ? state_code : state
  end

  def flexible_country
{'fraction_non_alphanumeric': 0.11798042246264812, 'fraction_numerical': 0.0015455950540958269, 'mean_word_length': 3.7761377613776137, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6571646', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1250, 'n_words': 258}