// Generated by CoffeeScript 1.7.1
var parser, sprintf, valueParse;

valueParse = require('../value-parser');

sprintf = require('sprintf').sprintf;

parser = function(buffer, columnsMetaData, options) {
  var column, columnMetaData, columns, value, _i, _len;
  columns = options.useColumnNames ? {} : [];
  for (_i = 0, _len = columnsMetaData.length; _i < _len; _i++) {
    columnMetaData = columnsMetaData[_i];
    value = valueParse(buffer, columnMetaData, options);
    column = {
      value: value,
      metadata: columnMetaData
    };
    if (options.useColumnNames) {
      if (columns[columnMetaData.colName] == null) {
        columns[columnMetaData.colName] = column;
      }
    } else {
      columns.push(column);
    }
  }
  return {
    name: 'ROW',
    event: 'row',
    columns: columns
  };
};

module.exports = parser;
