# all files / features/FeatureEditor/Models/ StepDeclarationModel.js

29.41% Statements 5/17
100% Branches 0/0
0% Functions 0/7
29.41% Lines 5/17

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42

    1

    1

    1

    1

    1

     'use strict';

    // Utilities:
    var _ = require('lodash');

    // Module:
    var FeatureEditor = require('../FeatureEditor');

    var createStepDeclarationModelConstructor = function () {
        var StepDeclarationModel = function StepDeclarationModel () {
            Object.defineProperties(this, {
                feature: {
                    get: function () {
                        return toFeature.call(this);
                    }
                }
            });

            this.type = _.first(this.types);
            this.step = '';
        };

        StepDeclarationModel.prototype.types = ['Given', 'When', 'Then', 'And', 'But'];

        StepDeclarationModel.getExampleVariableNames = _.memoize(function (step) {
            return _.chain(step.match(new RegExp('<.+?>', 'g')))
            .map(function (result) {
                return result.replace(/^</, '').replace(/>$/, '');
            }).value();
        });

        return StepDeclarationModel;

        function toFeature () {
            return this.type + ' ' + this.step;
        }
    };

    FeatureEditor.factory('StepDeclarationModel', function () {
        return createStepDeclarationModelConstructor();
    });