<commit_before>require 'json'

module YahooApiQuery
  API_QUERY_URL = "http://query.yahooapis.com/v1/public/yql?q="
  
  module Finance
    FINANCE_DATABASE = "yahoo.finance.quotes"
    DATATABLE = "&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
    
    class Query                       
      attr_reader :response
      def initialize(tickers)
        @tickers = tickers                                   
        uri = URI(build_query_uri)  
        @response = Net::HTTP.get_response(uri)
      end  

      def count
        JSON.parse(@response.body)['query']['count']    
      end

      def quotes                                               
        quote_data = JSON.parse(@response.body)['query']['results']['quote']        
        quote_data = [quote_data] if count == 1
        quote_data.each do |quote|
          quote['quoted_at']= JSON.parse(@response.body)['query']['created']
        end      
      end

      private

      def build_query_uri
        select_data_from = "select symbol, Ask, Bid from "
        for_these_symbols = " where symbol in (#{parse_tickers})"
        base_query =  API_QUERY_URL + select_data_from + FINANCE_DATABASE + 
            for_these_symbols
        query = URI.encode(base_query) + "&format=json" + DATATABLE
      end     

      def parse_tickers
        "\"#{@tickers.join("\", \"")}\""    
      end
    end

  end
end<commit_msg>Extracts a couple of private helper methods<commit_after>require 'json'

module YahooApiQuery
  API_QUERY_URL = "http://query.yahooapis.com/v1/public/yql?q="
  
  module Finance
    FINANCE_DATABASE = "yahoo.finance.quotes"
    DATATABLE = "&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"
    
    class Query                       
      attr_reader :response
      def initialize(tickers)
        @tickers = tickers                                   
        uri = URI(build_query_uri)  
        @response = Net::HTTP.get_response(uri)
      end  

      def count
        JSON.parse(@response.body)['query']['count']    
      end

      def quotes                                               
        quote_data = JSON.parse(@response.body)['query']['results']['quote']        
        quote_data = [quote_data] if count == 1
        quote_data.each do |quote|
          quote['quoted_at']= JSON.parse(@response.body)['query']['created']
        end      
      end

      private

      def build_query_uri
        base_query =  API_QUERY_URL + select_data_from + FINANCE_DATABASE + 
            for_these_symbols
        query = URI.encode(base_query) + "&format=json" + DATATABLE
      end     

      def for_these_symbols
        " where symbol in (\"#{@tickers.join("\", \"")}\")"    
      end
      
      def select_data_from
        "select symbol, Ask, Bid from "        
      end
    end

  end
end
{'fraction_non_alphanumeric': 0.10502121640735503, 'fraction_numerical': 0.004243281471004243, 'mean_word_length': 1.800990099009901, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4474783', 'n_tokens_mistral': 880, 'n_tokens_neox': 842, 'n_words': 157}