<commit_before>(function() {
  var selectOption = function(selector, value) {
    var options = $('option', selector);
    options.filter(function() {
      return ($(this).text() == value);
    }).prop('selected', true);
  };

  var highlight = function(selector) {
    $(selector).effect('highlight', 1500);
  };

  var setVAT = function(value) {
    var selector = '#purchase_sales_tax_rate';
    selectOption(selector, value);
    highlight(selector);
  };

  var setEcStatus = function(value) {
    var ecStatusOptions = {
      'Non-EC': '#bank_account_entry_ec_status_',
      'EC Goods': '#bank_account_entry_ec_status_2',
      'EC Services': '#bank_account_entry_ec_status_1'
    };

    var ecStatusSelector = ecStatusOptions[value];
    $(ecStatusSelector).prop('checked', true);
    highlight('#ec_status_options');
  };

  var setCategory = function(value) {
    var selector = $('#spending_category');
    selectOption(selector, value);
    highlight(selector);
  };

  var setDescription = function(value) {
    var selector = '#description';
    var descriptionField = $(selector);
    descriptionField.val(value);
    highlight(selector);
  };

  var promptForAnAttachment = function() {
    var selector = '#attachment_form h2';
    $(selector).text('Now upload an attachment!');
    $(selector).css('color', '#f00');
    highlight(selector);
  }

  var tryToExplainTransaction = function() {
    var unexplainedTransactionText = $('.transaction.unexplained').text();

    if (unexplainedTransactionText) {
      var rulesURL = 'https://rawgit.com/freerange/free_agent_transaction_explainer/master/rules.json';
      $.getJSON(rulesURL, function(rules) {
        $(rules).each(function(index, rule) {
          var textToMatch = rule['textToMatch'];
          var description = rule['description'];
          var vat = rule['vat'];
          var category = rule['category'];
          var shouldHaveAttachment = rule['shouldHaveAttachment'];
          var ecStatus = rule['ecStatus'];

          console.log('Testing: ' + textToMatch);
          if (unexplainedTransactionText.match(textToMatch)) {
            console.log('Found: ' + description);

            setVAT(vat);
            setEcStatus(ecStatus);
            setCategory(category);
            setDescription(description);
            if (shouldHaveAttachment) {
              promptForAnAttachment();
            };

            return false; // We don't need to continue having found a match
          };<commit_msg>Simplify by using object properties instead of dictionary lookup.<commit_after>(function() {
  var selectOption = function(selector, value) {
    var options = $('option', selector);
    options.filter(function() {
      return ($(this).text() == value);
    }).prop('selected', true);
  };

  var highlight = function(selector) {
    $(selector).effect('highlight', 1500);
  };

  var setVAT = function(value) {
    var selector = '#purchase_sales_tax_rate';
    selectOption(selector, value);
    highlight(selector);
  };

  var setEcStatus = function(value) {
    var ecStatusOptions = {
      'Non-EC': '#bank_account_entry_ec_status_',
      'EC Goods': '#bank_account_entry_ec_status_2',
      'EC Services': '#bank_account_entry_ec_status_1'
    };

    var ecStatusSelector = ecStatusOptions[value];
    $(ecStatusSelector).prop('checked', true);
    highlight('#ec_status_options');
  };

  var setCategory = function(value) {
    var selector = $('#spending_category');
    selectOption(selector, value);
    highlight(selector);
  };

  var setDescription = function(value) {
    var selector = '#description';
    var descriptionField = $(selector);
    descriptionField.val(value);
    highlight(selector);
  };

  var promptForAnAttachment = function() {
    var selector = '#attachment_form h2';
    $(selector).text('Now upload an attachment!');
    $(selector).css('color', '#f00');
    highlight(selector);
  }

  var tryToExplainTransaction = function() {
    var unexplainedTransactionText = $('.transaction.unexplained').text();

    if (unexplainedTransactionText) {
      var rulesURL = 'https://rawgit.com/freerange/free_agent_transaction_explainer/master/rules.json';
      $.getJSON(rulesURL, function(rules) {
        $(rules).each(function(index, rule) {
          console.log('Testing: ' + rule.textToMatch);
          if (unexplainedTransactionText.match(rule.textToMatch)) {
            console.log('Found: ' + rule.description);

            setVAT(rule.vat);
            setEcStatus(rule.ecStatus);
            setCategory(rule.category);
            setDescription(rule.description);
            if (rule.shouldHaveAttachment) {
              promptForAnAttachment();
            };

            return false; // We don't need to continue having found a match
          };
{'fraction_non_alphanumeric': 0.13750780112336175, 'fraction_numerical': 0.003744539213646765, 'mean_word_length': 3.1918047079337404, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '948046', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1319, 'n_words': 268}