/**
 * Class of order-by part of the query.
 *
 * @module ember-flexberry-data
 * @namespace Query
 * @class OrderByClause
 */
export default class OrderByClause {
  /**
   * @param clause
   * @class Query.OrderByClause
   * @constructor
   */
  constructor(clause) {
    this._clause = [];
    if (clause) {
      clause.split(',').forEach((i) => {
        let s = i.trim().split(' ');
        let name;
        let direction = s[s.length - 1];
        if (direction === 'asc' || direction === 'desc') {
          name = s.slice(0, s.length - 1).join(' ');
        } else {
          name = s.slice(0, s.length).join(' ');
          direction = '';
        }

        this._clause.push({ name, direction });
      });
    }
  }

  /**
    Count elements for sorting.

    @attribute length
    @type {Number}
    @public
   */
  get length() {
    return this._clause.length;
  }

  /**
    Returns object with parameters for sorting.

    @method attribute
    @param {Number} index Index element in array.
    @return {Object} Object with parameters for sorting.
   */
  attribute(index) {
    return this._clause[index];
  }
}

@@ -289,28 +289,8 @@
 %5B%5D;%0A
-    if (clause) %7B%0A  
     
@@ -324,18 +324,16 @@
 i) =%3E %7B%0A
-  
       le
@@ -355,26 +355,24 @@
 split(' ');%0A
-  
       let na
@@ -377,26 +377,24 @@
 name;%0A      
-  
 let directio
@@ -414,18 +414,16 @@
 h - 1%5D;%0A
-  
       if
@@ -471,18 +471,16 @@
 esc') %7B%0A
-  
         
@@ -528,18 +528,16 @@
 ;%0A      
-  
 %7D else %7B
@@ -537,18 +537,16 @@
  else %7B%0A
-  
         
@@ -580,26 +580,24 @@
 .join(' ');%0A
-  
         dire
@@ -614,23 +614,19 @@
 ;%0A      
-  
 %7D%0A%0A
-  
       th
@@ -671,20 +671,12 @@
     
-  
 %7D);%0A
-    %7D%0A
   %7D%0A

fix order-by-clause not check empty