<commit_before>module GeocodedByAddress


  if Rails.env.test?
    def geocoder_by_address
      nil
    end
  else
    def geocoder_by_address
      geocoded_by :address do |object, geocoder_results|
        geocoder = geocoder_results.first

        if geocoder
          object.latitude = geocoder.latitude
          object.longitude = geocoder.longitude
          object.route = geocoder.address_components_of_type(:route).first["short_name"] unless geocoder.address_components_of_type(:route).blank?
          object.neighborhood_name = geocoder.address_components_of_type(:neighborhood).first["long_name"] unless geocoder.address_components_of_type(:neighborhood)
          object.city_name = geocoder.city
          object.state_name = geocoder.state
          object.state_code = geocoder.state_code
          object.country_code = geocoder.country_code
          object.country_name = geocoder.country
          object.postal_code = geocoder.postal_code
          object.street_number = geocoder.street_number
          object.full_address = geocoder.address
          object.formatted_address = "#{geocoder.address_components_of_type(:route).first["short_name"]}, #{geocoder.street_number} - #{geocoder.address_components_of_type(:neighborhood).first["long_name"]}" unless geocoder.address_components_of_type(:neighborhood) && geocoder.address_components_of_type(:route)
        end
      end

      after_validation :geocode, unless: 'address.nil?'
    end
  end

end<commit_msg>Created method get_geocoder_for_route to get name of street on geocoded if route component do not exist<commit_after>module GeocodedByAddress


  if Rails.env.test?
    def geocoder_by_address
      nil
    end
  else
    def geocoder_by_address
      geocoded_by :address do |object, geocoder_results|
        geocoder = geocoder_results.first

        if geocoder
          object.latitude = geocoder.latitude
          object.longitude = geocoder.longitude
          object.route = get_geocoder_for_route(geocoder)
          object.neighborhood_name = geocoder.address_components_of_type(:neighborhood).first["long_name"] if geocoder.address_components_of_type(:neighborhood)
          object.city_name = geocoder.city
          object.state_name = geocoder.state
          object.state_code = geocoder.state_code
          object.country_code = geocoder.country_code
          object.country_name = geocoder.country
          object.postal_code = geocoder.postal_code
          object.street_number = geocoder.street_number
          object.full_address = geocoder.address
          object.formatted_address = "#{get_geocoder_for_route(geocoder)}, #{geocoder.street_number} - #{geocoder.address_components_of_type(:neighborhood).first["long_name"]}" if geocoder.address_components_of_type(:neighborhood) && geocoder.address_components_of_type(:route)
        end
      end

      after_validation :geocode, unless: 'address.nil?'
    end
  end


  private

  def get_geocoder_for_route(geocoder)
    route_component = geocoder.address_components_of_type(:route)
    bus_station_component = geocoder.address_components_of_type(:bus_station)

    if route_component.empty?
      bus_station_component.first["short_name"]
    else
      route_component.first["short_name"]
    end

  end

end
{'fraction_non_alphanumeric': 0.07736826073713067, 'fraction_numerical': 0.0, 'mean_word_length': 3.5359116022099446, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1652196', 'n_tokens_mistral': 1029, 'n_tokens_neox': 997, 'n_words': 154}