<commit_before>require 'geocoder'

module Calabash

  # An API for setting the location of your app.
  module Location
    # Simulates gps location of the device/simulator.
    # @note Seems UIAutomation is broken here on physical devices on iOS 7.1
    #
    # @example
    #  set_location({latitude: 48.8567, longitude: 2.3508})
    #
    # @example
    #  set_location(coordinates_for_place('The little mermaid, Copenhagen'))
    #
    # @param [Hash] location The location to simulate.
    # @raise [ArgumentError] If location is not a hash and does not contain a
    #  latitude and longitude key.
    def set_location(location)
      unless location.is_a?(Hash)
        raise ArgumentError, "Expected location to be a Hash, not '#{location.class}'"
      end

      unless location[:latitude] || location[:longitude]
        raise ArgumentError, 'You must supply :latitude and :longitude'
      end

      Calabash::Internal.with_default_device {|device| device.set_location(location)}
    end

    # Get the latitude and longitude for a certain place, resolved via Google
    # maps api. This hash can be used in `set_location`.
    #
    # @example
    #  coordinates_for_place('The little mermaid, Copenhagen')
    #  # => {:latitude => 55.6760968, :longitude => 12.5683371}
    #
    # @return [Hash] Latitude and longitude for the given place
    # @raise [RuntimeError] If the place cannot be found
    def coordinates_for_place(place)
      result = Geocoder.search(place)

      if result.empty?
        raise "No result found for '#{place}'"
      end

      {latitude: result.first.latitude,
       longitude: result.first.longitude}
    end
  end<commit_msg>Cleanup Location<commit_after>require 'geocoder'

module Calabash

  # An API for setting the location of your app.
  module Location
    # Simulates gps location of the device/simulator.
    # @note Seems UIAutomation is broken here on physical devices on iOS 7.1
    #
    # @example
    #  set_location(latitude: 48.8567, longitude: 2.3508)
    #
    # @example
    #  set_location(coordinates_for_place('The little mermaid, Copenhagen'))
    #
    # @param [Number] latitude The latitude of the location to simulate.
    # @param [Number] longitude The longitude of the location to simulate.
    # @raise [ArgumentError] If not given a latitude or longitude key.
    def set_location(latitude: nil, longitude: nil)
      unless latitude
        raise ArgumentError, "Expected latitude to be a number, not '#{latitude.class}'"
      end

      unless longitude
        raise ArgumentError, "Expected longitude to be a number, not '#{longitude.class}'"
      end

      Calabash::Internal.with_default_device {|device| device.set_location(latitude: latitude, longitude: longitude)}
    end

    # Get the latitude and longitude for a certain place, resolved via Google
    # maps api. This hash can be used in `set_location`.
    #
    # @example
    #  coordinates_for_place('The little mermaid, Copenhagen')
    #  # => {:latitude => 55.6760968, :longitude => 12.5683371}
    #
    # @return [Hash] Latitude and longitude for the given place
    # @raise [RuntimeError] If the place cannot be found
    def coordinates_for_place(place_name)
      result = Geocoder.search(place_name)

      if result.empty?
        raise "No result found for '#{place}'"
      end

      {latitude: result.first.latitude,
       longitude: result.first.longitude}
    end
  end
{'fraction_non_alphanumeric': 0.08866279069767442, 'fraction_numerical': 0.01802325581395349, 'mean_word_length': 3.0673758865248226, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2232045', 'n_tokens_mistral': 1082, 'n_tokens_neox': 994, 'n_words': 343}