<commit_before>require 'active_support'
require 'logger'
require 'net/http'
require 'rack'

class GoogleMapsGeocoder
  # Returns the complete formatted address with standardized abbreviations.
  attr_reader :formatted_address
  # Returns the formatted street address with standardized abbreviations.
  attr_reader :formatted_street_address
  # Self-explanatory
  attr_reader :city, :country_long_name, :country_short_name, :county, :lat, :lng, :postal_code, :state_long_name, :state_short_name

  # Instance Methods: Overrides ====================================================================

  # Geocodes the specified address and wraps the results in a geocoder object.
  #
  # ==== Attributes
  #
  # * +data+ - a geocodable address
  #
  # ==== Examples
  #
  #    white_house = GoogleMapsGeocoder.new('1600 Pennsylvania Washington')
  #    white_house.formatted_address
  #     => "1600 Pennsylvania Ave NW, Washington D.C., DC 20500, USA"
  def initialize data
    if data.is_a? String
      response = Net::HTTP.get_response(URI.parse("http://maps.googleapis.com/maps/api/geocode/json?address=#{Rack::Utils.escape(data)}&sensor=false"))
      @json = ActiveSupport::JSON.decode(response.body)
      raise "Geocoding \"#{data}\" exceeded query limit! Google returned...\n#{@json.inspect}" if @json.blank? || @json['status'] != 'OK'
    else
      @json = data
      address = data['formatted_address']
    end

    logger = Logger.new(STDERR)
    logger.info('GoogleMapsGeocoder') { "Geocoded \"#{address}\" and Google returned...\n#{@json.inspect}" }

    @city, @country_short_name, @country_long_name, @county, @formatted_address, @formatted_street_address, @lat, @lng, @postal_code, @state_long_name, @state_short_name = parse_city, parse_country_short_name, parse_country_long_name, parse_county, parse_formatted_address, parse_formatted_street_address, parse_lat, parse_lng, parse_postal_code, parse_state_long_name, parse_state_short_name
  end

  # Instance Methods ===============================================================================<commit_msg>Fix logger to use 'data' instead of the old 'address' param<commit_after>require 'active_support'
require 'logger'
require 'net/http'
require 'rack'

class GoogleMapsGeocoder
  # Returns the complete formatted address with standardized abbreviations.
  attr_reader :formatted_address
  # Returns the formatted street address with standardized abbreviations.
  attr_reader :formatted_street_address
  # Self-explanatory
  attr_reader :city, :country_long_name, :country_short_name, :county, :lat, :lng, :postal_code, :state_long_name, :state_short_name

  # Instance Methods: Overrides ====================================================================

  # Geocodes the specified address and wraps the results in a geocoder object.
  #
  # ==== Attributes
  #
  # * +data+ - a geocodable address
  #
  # ==== Examples
  #
  #    white_house = GoogleMapsGeocoder.new('1600 Pennsylvania Washington')
  #    white_house.formatted_address
  #     => "1600 Pennsylvania Ave NW, Washington D.C., DC 20500, USA"
  def initialize data
    if data.is_a? String
      response = Net::HTTP.get_response(URI.parse("http://maps.googleapis.com/maps/api/geocode/json?address=#{Rack::Utils.escape(data)}&sensor=false"))
      @json = ActiveSupport::JSON.decode(response.body)
      raise "Geocoding \"#{data}\" exceeded query limit! Google returned...\n#{@json.inspect}" if @json.blank? || @json['status'] != 'OK'
    else
      @json = data
      address = data['formatted_address']
    end

    logger = Logger.new(STDERR)
    logger.info('GoogleMapsGeocoder') { "Geocoded \"#{data}\" and Google returned...\n#{@json.inspect}" }

    @city, @country_short_name, @country_long_name, @county, @formatted_address, @formatted_street_address, @lat, @lng, @postal_code, @state_long_name, @state_short_name = parse_city, parse_country_short_name, parse_country_long_name, parse_county, parse_formatted_address, parse_formatted_street_address, parse_lat, parse_lng, parse_postal_code, parse_state_long_name, parse_state_short_name
  end

  # Instance Methods ===============================================================================
{'fraction_non_alphanumeric': 0.17743858812306224, 'fraction_numerical': 0.006200810875268304, 'mean_word_length': 5.383561643835616, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3799963', 'n_tokens_mistral': 1331, 'n_tokens_neox': 1254, 'n_words': 284}