<commit_before>class Location < ApplicationRecord
  belongs_to :locatable, polymorphic: true, optional: true
  before_save :assign_coordinates
  acts_as_mappable default_units: :kms,
    distance_field_name: :distance,
    lat_column_name: :latitude,
    lng_column_name: :longitude

  def full_address
    [
      try(:address),
      try(:city),
      try(:region),
      try(:country)
    ].join(", ")
  end

  def coordinates
    latitude == 0.0 && longitude == 0.0 ? [] : [latitude, longitude]
  end

  def url
    "https://maps.google.com/?q=#{latitude},#{longitude}"
  end

  class << self
    def build_from_ip(ip)
      result = search(ip)
      new(
        address: result.address,<commit_msg>return nil if location lookup fails.<commit_after>class Location < ApplicationRecord
  belongs_to :locatable, polymorphic: true, optional: true
  before_save :assign_coordinates
  acts_as_mappable default_units: :kms,
    distance_field_name: :distance,
    lat_column_name: :latitude,
    lng_column_name: :longitude

  def full_address
    [
      try(:address),
      try(:city),
      try(:region),
      try(:country)
    ].join(", ")
  end

  def coordinates
    latitude == 0.0 && longitude == 0.0 ? [] : [latitude, longitude]
  end

  def url
    "https://maps.google.com/?q=#{latitude},#{longitude}"
  end

  class << self
    def build_from_ip(ip)
      result = search(ip)
      return nil if result.nil?
      new(
        address: result.address,
{'fraction_non_alphanumeric': 0.12098427887901572, 'fraction_numerical': 0.005468215994531784, 'mean_word_length': 3.1123595505617976, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7111970', 'n_tokens_mistral': 493, 'n_tokens_neox': 474, 'n_words': 108}