<commit_before>require 'spot_rate/version'

class SpotRate
  class CurrencyNotFound < RuntimeError; end

  attr_accessor :from_currency, :to_currency

  def self.available_converters
    @@available_converters ||= {}
  end

  def self.register_currency_converter converter_key, converter_class
    self.available_converters[converter_key] = converter_class
  end

  def self.[](hash)
    raise ArgumentError unless hash.size <= 2

    new(from_currency: hash.keys.first, to_currency: hash.values.first)
      .use(hash[:use] || hash[:using] || :default)
      .spot_rate
  end

  def initialize config = {}
    @from_currency = config[:from_currency]
    @to_currency   = config[:to_currency]
  end

  def use requested_converter_key
    self.class
        .available_converters[requested_converter_key]
          .new(@from_currency, @to_currency)
  end

  def spot_rate
    default_currency_converter.spot_rate
  end

  def default_currency_converter
    use(:default)
  end
end

require 'spot_rate/google_currency_converter'
SpotRate.register_currency_converter :default, SpotRate::GoogleCurrencyConverter<commit_msg>Ensures requested converter key is a symbol<commit_after>require 'spot_rate/version'

class SpotRate
  class CurrencyNotFound < RuntimeError; end

  attr_accessor :from_currency, :to_currency

  def self.available_converters
    @@available_converters ||= {}
  end

  def self.register_currency_converter converter_key, converter_class
    self.available_converters[converter_key.to_sym] = converter_class
  end

  def self.[](hash)
    raise ArgumentError unless hash.size <= 2

    new(from_currency: hash.keys.first, to_currency: hash.values.first)
      .use(hash[:use] || hash[:using] || :default)
      .spot_rate
  end

  def initialize config = {}
    @from_currency = config[:from_currency]
    @to_currency   = config[:to_currency]
  end

  def use requested_converter_key
    self.class
        .available_converters[requested_converter_key.to_sym]
        .new(@from_currency, @to_currency)
  end

  def spot_rate
    default_currency_converter.spot_rate
  end

  def default_currency_converter
    use(:default)
  end
end

require 'spot_rate/google_currency_converter'
SpotRate.register_currency_converter :default, SpotRate::GoogleCurrencyConverter
{'fraction_non_alphanumeric': 0.08150744960560911, 'fraction_numerical': 0.0008764241893076249, 'mean_word_length': 4.422802850356295, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6839314', 'n_tokens_mistral': 734, 'n_tokens_neox': 702, 'n_words': 141}