processSnippets.js

/**
 * Created by WORKER on 01-09-2015.
 */
var financeCalculator = require('./financeCalculator')

/**
 * Process finance records and store the result
 * @param  {String} type     Type of finance record
 * @param  {Array} snippets  Records to be processed
 * @param  {Object} result   Stores the result of calculation
 */
function processSnippets(type, snippets, result) {
  var value = 0
  switch (type) {
    case 'SPNT':
      value = financeCalculator.spent(snippets)
      result[type] = parseInt(value, 10)
      break
    case 'RCVD':
      value = financeCalculator.received(snippets)
      result[type] = parseInt(value, 10)
      break
    case 'BRWD':
      value = financeCalculator.borrowed(snippets)
      result[type] = parseInt(value, 10)
      break
    case 'LENT':
      value = financeCalculator.lent(snippets)
      result[type] = parseInt(value, 10)
      break
    default:
  }
}

module.exports = processSnippets