<commit_before>/**
 * Daimyo - core Daimyo functionality
 * Copyright (c)2011, by <NAME> <<EMAIL>>
 * Licensed under MIT license (see LICENSE)
 */

var settings = require('./config').settings;
var debug = require('./config').debug;
var check = require('./check');
var DaimyoError = require('./error');
var authpost = require('./authpost');
var xmlutils = require('./xmlutils');
var tokenRe = /^[0-9a-f]{24}$/;
var daimyo = exports;

function normalizeYear(order, year) {
  return (Math.floor(new Date().getFullYear() / order) * order) + year;
}

/**
 * Creates a new payment method instance<commit_msg>Implemented toSamurai method that converts Daimyo-specific keys to Samurai node names.<commit_after>/**
 * Daimyo - core Daimyo functionality
 * Copyright (c)2011, by <NAME> <<EMAIL>>
 * Licensed under MIT license (see LICENSE)
 */

var settings = require('./config').settings;
var debug = require('./config').debug;
var check = require('./check');
var DaimyoError = require('./error');
var authpost = require('./authpost');
var xmlutils = require('./xmlutils');
var tokenRe = /^[0-9a-f]{24}$/;
var daimyo = exports;

function normalizeYear(order, year) {
  return (Math.floor(new Date().getFullYear() / order) * order) + year;
}

/**
 * Mappings between between Daimyo field names and Samurai node names
 */
var MAPPINGS = {
  number: 'card_number',
  csc: 'cvv',
  year: 'expiry_year',
  month: 'expiry_month',
  issuer: 'card_type'
};

/**
 * Remaps the Daimyo field names to Samurai node names in an object
 *
 * @param {Object} o Daimyo object
 * @returns {Object} Object with remapped fields
 */
daimyo.toSamurai = function(o) {
  var remapped = {};

  Object.keys(o).forEach(function(key) {
    if (MAPPINGS.hasOwnProperty(key)) {
      remapped[MAPPINGS[key]] = o[key];
    } else {
      remapped[key] = o[key];
    }
  });

  return remapped;
};

/**
 * Creates a new payment method instance
{'fraction_non_alphanumeric': 0.16395165528113506, 'fraction_numerical': 0.008407777193904361, 'mean_word_length': 4.0638297872340425, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3983459', 'n_tokens_mistral': 629, 'n_tokens_neox': 612, 'n_words': 178}