all files / app/matches/ matchOpponentTeam.directive.js

100% Statements 23/23
100% Branches 11/11
100% Functions 6/6
100% Lines 22/22
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64                                                                30× 30× 30×     20× 20× 10× 10×   20×              
/**
 * @ngdoc directive
 * @name app.matches.directive:feMatchOpponentTeam
 * @restrict E
 * @description
 * Display the name of a team in a match
 *
 */
 
(function () {
  'use strict';
 
  angular
    .module('app.matches')
    .directive('feMatchOpponentTeam', directiveFunc);
 
  /** @ngInject */
  function directiveFunc() {
    var directive = {
      restrict: 'E',
      templateUrl: 'app/matches/matchOpponentTeam.html',
      controller: Controller,
      controllerAs: 'vm',
      bindToController: true,
      scope: {
        team: '=',
        punctuation: '@'
      }
    };
 
    return directive;
  }
 
  function Controller() {
    var vm = this;
 
    activate();
 
    function activate() {
      vm.teamName = teamName;
      vm.suffix = suffix;
    }
 
    function teamName() {
      var result = vm.team.name;
      if (!result) result = 'Unnamed team';
      return result;
    }
    
    function suffix() {
      var punctuation = vm.punctuation || '';
      if (punctuation) {
        var name = teamName();
        if (name && punctuation == '.' && name.charAt(name.length - 1) == '.')
          punctuation = '';
      }
      return punctuation;
    }
 
  }
 
 
})();