/**
 * Helper to read file.
 * @module ci.helpers.fileReadHelper
 * @author ci.worker.generateStructure
 */

var fs = require('fs'),
    os = require('os');

/**
 * @function ci.helpers.fileReadHelper.readLine
 * @param {string} filename - File name to read.
 * @param {number} [lineNumber] - Line number to read.
 * @param {boolean} [shouldTrim] - Should trim or not.
 * @returns {string} - Line data.
 */
exports.readLine = function (filename, lineNumber, shouldTrim) {
    var exists = fs.existsSync(filename);
    if (!exists) return null;
    var content = fs.readFileSync(filename).toString(),
        line = content.split(os.EOL)[lineNumber || 0];
    if (shouldTrim) {
        line = line && line.trim();
    }
    return line;
};