<commit_before>module SPF
  module Gateway

    #Simple module for degree-radians conversion
    class ::Float
      def to_rad
        self / 180.0 * Math::PI
      end
    end

    # CLASS GPS

    # Cento = {   latitude: 44.8332215, longitude: 11.5992085 }
    # Ferrara = { latitude: 48.133333, longitude: 11.566667 }
    # d = SPF::Gateway::GPS.new(Cento,Ferrara)
    # d.distance()
    # => 27.1 (in Km)

    class GPS
      attr_reader :lat1, :lon1, :lat2, :lon2 #, :from, :to
      RADIUS = 6371

      # from = { latitude: 100, longitude: 20 }
      # to = { latitude: 100, longitude: 20 }
      def initialize(from, to)
        @lat1 = from[:lat].to_f.to_rad
        @lat2 = to[:lat].to_f.to_rad
        @lon1 = from[:lon].to_f.to_rad
        @lon2 = to[:lon].to_f.to_rad
      end

      def distance(type = 'haversine')
        begin
          self.send(type.to_sym)
        rescue
          raise NotImplementedError, "#{self.class.name}: The type you have requested is not implemented, 
                                      try 'cosines' or 'approximation', or without params for 'haversine'"
        end
      end
      
    
      private

      def haversine
        d_lat = @lat1 - @lat2
          # (@from[:latitude] -  @to[:latitude]).to_rad
        d_lon = @lon1 - @lon2
          # (@from[:longitude] - @to[:longitude]).to_rad
        a = Math::sin(d_lat / 2) * Math::sin(d_lat / 2) +
            Math::sin(d_lon / 2) * Math::sin(d_lon / 2) *
            Math::cos(lat1) * Math::cos(lat2)
        c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
        # p RADIUS * c
        dist = RADIUS * c
        puts dist
        return dist
      end

    end
  end
end<commit_msg>Removed old comments, fixed code style, removed puts()<commit_after>module SPF
  module Gateway

    #Simple monkey patch that adds degree-radians conversion to the Float class
    class ::Float
      def to_rad
        self / 180.0 * Math::PI
      end
    end

    
    class GPS
      
      RADIUS = 6371
      
      attr_reader :lat1, :lon1, :lat2, :lon2

      
      def initialize(from, to)
        @lat1 = from[:lat].to_f.to_rad
        @lat2 = to[:lat].to_f.to_rad
        @lon1 = from[:lon].to_f.to_rad
        @lon2 = to[:lon].to_f.to_rad
      end

      # Returns the distance in KMs
      def distance(type = 'haversine')
        begin
          self.send(type.to_sym)
        rescue
          raise NotImplementedError, "#{self.class.name}: The type you have requested is not implemented, 
                                      try 'cosines' or 'approximation', or without params for 'haversine'"
        end
      end
      
    
      private

        def haversine
          d_lat = @lat1 - @lat2
          d_lon = @lon1 - @lon2
          a = Math::sin(d_lat / 2) * Math::sin(d_lat / 2) +
              Math::sin(d_lon / 2) * Math::sin(d_lon / 2) *
              Math::cos(lat1) * Math::cos(lat2)
          c = 2 * Math::atan2(Math::sqrt(a), Math::sqrt(1-a))
          RADIUS * c
        end

    end
  end
end
{'fraction_non_alphanumeric': 0.12017167381974249, 'fraction_numerical': 0.034664905909541105, 'mean_word_length': 1.7199281867145422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5257976', 'n_tokens_mistral': 1110, 'n_tokens_neox': 1022, 'n_words': 253}