<commit_before>module Straight
  module ExchangeRate

    class AverageRateAdapter

      # Takes exchange rate adapters instances as an arguments
      def initialize(*adapter_instances)
        @rates = []
        adapter_instances.each do |adapter|
          @rates << adapter.rate_for('USD')
        end
      end

      def calculate_avg_rate
        @rates.compact!
        @rates.inject {|sum, rate| sum + rate} / @rates.size
      end

    end

  end
end<commit_msg>Altered AverageRateAdapter to accept class names as an arguments, implemented raising CurrencyNotSupported if all adapters fail to get rates<commit_after>module Straight
  module ExchangeRate

    class AverageRateAdapter < Adapter

      # Takes exchange rate adapters instances or classes as an arguments
      def initialize(*adapters)
        @adapters = adapters.map{ |adapter| adapter.respond_to?(:new) ? adapter.new : adapter }
      end

      def rate_for(currency_code)
        rates = []
        @adapters.each do |adapter| 
          begin
            rates << adapter.rate_for(currency_code)
          rescue CurrencyNotSupported
            rates << nil
          end
        end

        unless rates.select(&:nil?).size == @adapters.size 
          rates.compact!
          rates.inject {|sum, rate| sum + rate} / rates.size
        else
          raise CurrencyNotSupported
        end
      end

    end

  end
end
{'fraction_non_alphanumeric': 0.06970128022759602, 'fraction_numerical': 0.0, 'mean_word_length': 2.219679633867277, 'pattern_counts': {'":': 0, '<': 10, '<?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': '978708', 'n_tokens_mistral': 395, 'n_tokens_neox': 365, 'n_words': 113}